r/cpp • u/According_Leopard_80 • Apr 09 '26
Writing only decoupled code
https://middleraster.github.io/DAG/HeaderOnlyNoForwardDeclarations.html
12
Upvotes
r/cpp • u/According_Leopard_80 • Apr 09 '26
View all comments
13
u/fdwr fdwr@github 🔍 Apr 09 '26
Interestingly this does not apply to class/struct methods, as the one area of C++ where you can define functions in a logically grouped order rather than strict call dependency order. The same does not apply to free functions, but then one cute hack to achieve order independence is to wrap them all inside the class as static methods (not recommending 😅), thus making the class essentially more of a namespace (too bad it doesn't work inside ordinary namespaces too, but there must some reasoning for delayed processing or two pass evaluation 🤷♂️).