So generally having
class A { ... };
class B { ... };
class C: public A, public B {}; // C inherits from A and B.
when we create an instance of C and want to pass it into some function ho do we check if class we pass to a function is extending A?
C
is defined as inheriting fromA
so there is no need to check:It is mandatory that an instance of
C
is also aA
(and aB
).However, if you have a function taking a
A
as a parameter, you can usedynamic_cast<>
to check if the instance is actually aC
:For this to work, however, the base class type must be polymorphic (it must have at least a virtual method).
The only time you'd need to do this is during compile time since implicit conversion works everywhere else. But if you want to see if some type T is a base of some type S then you can use SFINAE (or just use is_base_of<>):