子类覆盖父类的成员函数:
#include "stdafx.h" #include "iostream" class CAnimal { protected: int m_Age; int m_Weight; public: void move(); }; class CDog:public CAnimal { public: void move(); }; void CAnimal::move() { printf("animal is moving"); } void CDog::move() { printf("dog is moving"); } int main(int argc, char* argv[]) { CDog dog; dog.move(); //子类调用自身的move方法,父类的被覆盖掉 std::cout<<std::endl; dog.CAnimal::move(); //子类调用父类的成员函数 return 0; }