Search code examples
c++oopfunctionvirtual

c++ virtual function reimplementation


even i think that question is stupid. but i've a little experience.

i have a base class that has such method:

class A{  virtual void func(int)=0 };

and inherited class

    class  B :public A
  {  
     //how should i write?
    //a  
       virtual void func() {    implementation...}  

    //b
      void func() {implementation    } 
   //my target is to redefine a function of ansestor
 //i worry that variant b can  cover ansestor function and i will not redefine it
 //but what if i don't want that the function that was virtual in ansestor, will   be      virtual in subclass? 
i'm confused
}

i don't know that to do. if i don't need this virtual function complete


Solution

  • You ask, "what if i don't want that the function that was virtual in ansestor, will be virtual in subclass?"

    Sorry, but every function that is declared virtual in a base class, is also virtual in all derived classes.

    It actually doesn't matter whether you use the virtual keyword in the derived-class declaration. Options a and b are identical -- in both cases B::func is virtual.