samedi 20 avril 2019

How can I check whether a class inherits another class? [duplicate]

Suppose I'm writing the following templated function:

class A { /* ... */ };

// ... etc...

template<typename C>
void foo() {
    bool C_inherits_A = /* magic */;
    if (C_inherits_A) { do_something(); }        
    else { do_something_else(); }
}

We remember dynamic_cast from the olden days, but that isn't relevant here since there's no pointer, and I'm checking "downward", not "upward". Is there something simple with which to replace /* magic */ in the snippet above?

PS - There should definitely already be a dupe of this question, but I just could not find one so I wrote it up.

Aucun commentaire:

Enregistrer un commentaire