#include <iostream> using namespace std; class B { public: B(int x=0) { X=x; cout<<"B("<<x<<")\n"; } ~B() { cout<<"~B()\n"; } void print() { cout <<X<< " "; } private: int X; }; class D: public B { public: D (int x, int y):B(x) { Y=y; cout<<"D("<<x<<","<<y<<")\n"; } ~D() { cout<<"~D()\n"; } void print() //与基类中的成员函数同名!这个冲突如何解决的?! { B::print(); cout <<Y<<endl; } private: int Y; }; int main() { D d(11,22); d.print(); return 0; }
运行结果:
基类和派生类成员函数重名 基类成员函数会被自动屏蔽
原文地址:http://blog.csdn.net/ljd939952281/article/details/45950083