How to implement a private virtual function within derived classes?

Posted by Dane on Stack Overflow See other posts from Stack Overflow or by Dane
Published on 2010-03-16T14:53:57Z Indexed on 2010/03/16 15:01 UTC
Read the original article Hit count: 159

Filed under:
|
|

Hi,

I know why I want to use private virtual functions, but how exactly can I implement them?

For example:

class Base{
[...]
private:
 virtual void func() = 0;
[...]
}

class Derived1: puplic Base{
  void func() 
  { //short implementation is ok here
  }
} 

class Derived2: puplic Base{
  void func(); //long implementation elsewhere (in cpp file)
} 

[...] 

void Derived2::func()
{ //long implementation 
}

The first version is ok but not always possible. Isn't the second version simply name hiding? How do you define the Base::func() of Derived2, if you cannot do it within the class declaration of Dereived2?

Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about private-members