vendredi 23 novembre 2018

deleting or throwing compiler error when a virtual base function is called from a derived class in c++

I have the following code:

 class A
 {
 public:
      virtual void f(int a) = 0;
      virtual void f(int a, int b) = 0;
 };

 class B : public A
 {
 public:
      // do not want f(int a,int b) accessible
      void f(int a);
 };

 class C : public A
 {
 public:
      // do not want f(int a) accessible
      void f(int a, int b);
 };

I am aware that purely virtual functions cannot be deleted. Is there any way to disable these functions such that a compile time error occurs if an instance of B tries to call f(int,int) or when an instance of C tries to call f(int)

Aucun commentaire:

Enregistrer un commentaire