The library offers a class to be derived from with the derived class as a template argument.
Example:
class userclass : public lib::superclass<userclass>
{}
As you can see its quite a lot to type. And the “userclass” should always derive as public for it to work correctly. So i came up with two MACROs looking like this:
#define SUPER(x) public lib::superclass<x>
#define SUPERCLASS(x) class x : public lib::superclass<x>
The user can now type either of.
class userclass : SUPER(userclass)
{}
SUPERCLASS(userclass)
{}
But the main problem is that the macros SUPER and SUPERCLASS exist in the users global namespace as quick as the header is included.
Can/should i:
- Have a way of preserving the namespace requirement but still defaulting to public derives?
- Use the macros as they are.
- Simply require the user to write out the full “public lib::superclass”.
I’m using vs 11 and the library is targeted against windows developers.
The first rule of using macros is “Don’t, if there’s any other solution”. In this case, there is another solution, so get rid of them.
Secondly, your macros do way more harm than good, because people have no idea what they expand to by just reading it, whereas the full definition does. Seriously, you’re saving a truly minute number of characters for a truly hideous cost in readability. It’s far superior to simply write out the inheritance.