Changing the access specifier for a virtual function - page 2

 
Dominik Egert #:

Protected would be required if you have add() in a class between base and child.
No, as you have to override search() in this intermediate class.
 
Alain Verleyen #:
No, as you have to override search() in this intermediate class.
Only if you want to instantiate this class, right??

I have to check.
 

It should probably be something like this

class CAbstractFirstFloor
  {
protected:
   virtual int search() = 0;
public:
   void add()                { Alert(search());  }
  };

class CAbstractSecondFloor : public CAbstractFirstFloor
  {
private:
   int callSearch()          { return(search()); }
  };

class CChild : public CAbstractSecondFloor
  {
private:
   int search() override     { return(111);      }
  };
 
Dominik Egert #:
Only if you want to instantiate this class, right??

I have to check.

You could make it protected yes.

But it's still not needed, you can also redeclare the pure search() method in the new abstract class.

Not sure it really matters.

 
Vladislav Boyko: Can I change the access to a base class method by using a different access specifier when overriding the method in a descendant?
“When should virtual functions be public, protected, or private?” The short answer is: Rarely if ever, sometimes, and by default, respectively.
          Virtuality - Guru of the Week 9 September 2001.