I have a class that is suppose to be a base class:
template<int ID>
class BaseClass { ... };
How can I make a compile-time error appear if two classes try to inherit form this base class using the same value of ID. That is - this code is suppose to work:
class A : BaseClass<1> { ... }
class B : BaseClass<2> { ... }
But this code is suppose to cause an error:
class A : BaseClass<1> { ... }
class B : BaseClass<1> { ... }
How can one achieve this? Does BOOST_STATIC_ASSERT help?
I think that is impossible.
If it were possible, then we can make compiler to generate error for the following code as well, which is conceptually equivalent to your code.
struct Base {};
struct OtherBase {};
struct A : Base {}; //Base is used here!
struct B : Base {}; // error - used base class. please use some other base!
struct C : OtherBase {}; // ok - unused based!
Just guessing, but in case you want to generate unique type ids, you may want to check out this and this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With