c++ - Overload of pure virtual function -


i use pure virtual functions methods required code work well. therefore, create interfaces , other users implement derived classes. derived classes have these virtual functions public while additional methods should implemented private since code not call them. don't know if can considered practice of oop (are there design pattern?). anyway, question is: can user overload pure virtual function?

i.e.

class base { public:  base();  virtual ~base();  virtual void foo(int,double)=0; };  class derived: public base {  private:   // methods  public:  derived();  virtual ~derived();  virtual void foo(int, double, double); //this doesn't work  }; 

a solution be:

 virtual void foo(int,double,double=0)=0; 

in base class limited. think about?

these 2 functions different. latter not overriding first

virtual void foo(int,double)=0; virtual void foo(int, double, double); 

the second 1 new virtual function specific derived.

if put override @ end compile complain not overriding anything. c++11 check though.

virtual void foo(int, double, double) override; 

the user can override pure virtual function confirm use override @ end of function verify. in case second function can accessed using derived pointer or type. (although cannot instantiated unless pure virtual function overridden , implemented, untill abstract class). hence if not intended overidden further classes derives derived making virtual overhead anyway not overidding base method.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -