I (hopefully) have understood the purpose of a private virtual function, but I haven't understood why should I have a private pure virtual function! I mean, I have to define this function in all derived classes, but this way all the calls to this virtual pure will be a call to the one defined in the derived.
Suppose we have :
class Base{
public:
void foo(){ bar(); }
private:
virtual void bar() =0 {/*something*/}
};
A derived class of Base must define bar (or have it pure virtual, but forget this for one moment). Because Base::bar is private, it can't be used by the derived class. Because Base is abstract, i can't create Base object, therefore i can call foo only on derived classes, but this means that Base::bar will never be called! Sure, i could have defined foo:
void Base::foo(){
bar();
Base::bar();
}
But for what? It would not be better to define a non virtual private function with the body of bar (and replace Base::bar with it), and make the body of the pure virtual empty?
If so, why should I have bar private (and not protected)?
PS: I have tried to find a solution on internet, and i know there are posts like -> C++: Private virtual functions vs. pure virtual functions , but they help in understanding private virtual function, not private PURE virtual function. If I'm wrong, forgive me!