class BaseClass { public: virtual ~BaseClass() {} }; class DerivedClass : public BaseClass { }; DerivedClass dc; bool isDerived = dc.InheritsFrom("BaseClass");
#includeIn this example, we are using the ROOT data analysis framework's TObject class, which is the base class of all ROOT classes. We create a new class called MyClass, which is derived from TObject. We then create an object of MyClass and use the InheritsFrom method to check whether it is derived from TObject or not. The output will be true as MyClass is derived from TObject. Package Library: ROOT data analysis framework.class MyClass : public TObject { }; MyClass mc; bool isDerived = mc.InheritsFrom("TObject");