jeudi 22 avril 2021

How do I call generic variable's method when I specify T must be based of some class in C++?

class Base {
 public:
   void A() {}
};

class Derived: public Base {
  public:
   void B() {}
};

template <typename T, std::enable_if<std::is_base_of<Base, T>::value, int>::type = 0>
class SomeClass {
 public:
   T t;
   // I want to call method A() with variable 't'.
   void invoke() { t.A(); }
};

auto some = new someClass<Derived>();
// I want to call method B() when the 'T' specify to 'Derived'.
some->t.B();

How do I call the A() method when the 'T' must be based of class 'Base', and call the B() method when the 'T' in the class 'someClass' specify to 'Derived'?

Aucun commentaire:

Enregistrer un commentaire