Check if class is derived from a specific class (compile, runtime both answers available)

后端 未结 6 1859
不知归路
不知归路 2020-12-03 12:13

It is easier to explain on an example so,

class base {
//....
}

class derived1 : public base {
//...
}

In my library, there is a pointer o

6条回答
  •  不知归路
    2020-12-03 12:35

    Check if class is derived from a specific class (compile time)

    You can use std::is_base_of:

    #include 
    
    ....
    
    const bool isBase = std::is_base_of::value;
    

    isBase is true if TheOtherClass is derived from base.

提交回复
热议问题