I do not know if I understand your problem correctly, so let me repeat it with words ...
Problem: The given classes B and D determine if D subclass of B (or vice versa?)
Solution: use template magic! Well, seriously, you need to take a look at LOKI, an excellent template meta-programming library created by the legendary C ++ author Andrei Alexandruscu.
In particular, download LOKI and include the TypeManip.h header from it in the source code, then use the SuperSubclass class SuperSubclass as follows:
if(SuperSubClass<B,D>::value) { ... }
According to the documentation, SuperSubClass<B,D>::value will be true if B is the public base of D , or if B and D are aliases of the same type.
i.e. either D is a subclass of B or D is the same as B
Hope this helps.
change
Note that evaluating SuperSubClass<B,D>::value occurs at compile time, unlike some methods that use dynamic_cast , so thereβs no penalty for using this system at runtime.
Autodidact Nov 21 '08 at 16:43 2008-11-21 16:43
source share