mercredi 25 septembre 2019

How to call an implementation of an interface in c++ from another class?

I have an abstract class, let's say A, which contains a pure virtual function with an access specifier as protected. Another class, let's say B, overrides the interface and implement function List().

class A {
 public:
  ...
 protected:
  virtual std::vector<std::string> List() = 0;
}
class B: public A {
 protected:
  std::vector<std::string> List() override {
   //Implementation for the method
  }
}

My question is that now I have another class, C, which needs to call implemented interface List() from class B so that I can store the returned result in class C. How can I call an interface in class C?

PS: I can change the access specifier of the method to public in class B if that can solve the problem.

Aucun commentaire:

Enregistrer un commentaire