Saturday, 24 August 2013

About virtual function override in C++

About virtual function override in C++ References I\'m a little confused about the following situations, are they correct ways for the overriding of function copy but not overloading, or all of them are right? class Base{ public: virtual Base* copy(Base* b){...} }; class Derived:public Base{ public: virtual Base* copy(Base* b){...}//I know this should work // but how about the followings? //virtual Base* copy(Derived* b){...} //virtual Derived* copy(Base* b){...} //virtual Derived* copy(Derived* b){...} }; BTW, does the change of access right make any difference? say, I write the Derived class like this: class Derived:public Base{ private://or protected: virtual Base* copy(Base* b){...} ... };

No comments:

Post a Comment