I have some functions that can be grouped together, but do not belong to some object / entity and therefore cannot be considered as methods.
So, basically in this situation, I would create a new namespace and put the definitions in the header file, the implementation in the cpp file. Also (if necessary) I would create an anonymous namespace in this cpp file and put all the extra features that should not be included / included in my namespace interface there.
See the code below (maybe not a good example and might be better with a different software architecture, but I just can't come up with a better example ...)
Sample code ( header )
namespace algorithm { void HandleCollision(Object* object1, Object* object2); }
Sample Code ( cpp )
#include "header"
So far so good. I think this is a good way to manage my code, but I donβt know what to do if I have some template-based functions and want to do basically the same thing.
If I use templates, I have to put all my code in a header file. Ok, but how should I hide some implementation details?
I want to hide the RefractObject function from my interface, but I canβt just delete its declaration (just because I have all my code in the header file) ...
The only approach I came up with is something like:
Sample code ( header )
namespace algorithm {
Any ideas how to do this better in terms of code design?
c ++ design namespaces templates
Costantino rupert
source share