Is this the simplest way to determine if foo
is the same or derived from type T
bool Derives<T>(object foo)
{
return foo is T;
}
and an exact match would be
bool ExactMatch<T>(object foo)
{
return foo.GetType() == typeof(T);
}
C++ has no direct method to check one object is an instance of some class type or not. In Java, we can get this kind of facility. In C++11, we can find one item called is_base_of<Base, T>. This will check if the given class is a base of the given object or not.
The extends keyword in the Child class definition tells you it's a derived class.
1. A base class is an existing class from which the other classes are derived and inherit the methods and properties. A derived class is a class that is constructed from a base class or an existing class.
Inheritance in C++ The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object-Oriented Programming. Inheritance is a feature or a process in which, new classes are created from the existing classes.
I can't think of a simpler way :)
(and in 'answer' format, to please the trolls: "Yes")
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