程序代码:
#include "iostream" using std::endl; using std::cin; using std::cout; class Parent { public: int a; int b; public: void getParent() { cout << a << " " << b << endl; } }; class Child :public Parent { public: int a; int b; public: void getChild() { cout << a << " " << b << endl; } }; int main() { Child c1; c1.getParent(); //大哥问题在这,Child继承父类Parent,也继承了他的getParent()方法,那么用子类对象去调getParent方法, 调用的是父类的还是子类继承过来的方法呀?就是说调用的这个getParent方法属于父类还是子类? system("pause"); return 0; }