//覆盖成员函数 //rect.CShape::display()通过作用域限定符":"指定调用了基类中的成员函数. #include "stdafx.h" #include <iostream> using namespace std; class CShape { private: int m_color; public: CShape(int color=10); void display(); }; CShape::CShape(int color) { m_color = color; } void CShape::display() { cout << "This is a Shape" << endl; } class CRect:public CShape { private: int m_size; public: CRect(int size = 20); void display(); }; CRect::CRect(int size) { m_size = size; } void CRect::display() { cout << "This is a Rect "<< endl; } int main(int argc, char* argv[]) { //printf("Hello World!\n"); CShape shape; shape.display(); CRect rect; rect.display(); rect.CShape::display(); return 0; }
http://pythonschool.com/python/88.html