我说一下我的看法:
一、在derived(int a,int b):b(a)这一构造函数应该改为derived(int a,int b):base(a);
二、在class derived:private base这一句中,将base定义为了私有成员,所以派生类derived的对象无法访问base的成员函数。
所以我将这一句改为class derived :public base
然后下边的调用改成了obj.base::show();
附代码
#include
using namespace std;
class base
{
private:
int m;
public:
base(int a) :m(a) {}
void show() const
{
cout << "m:" << m << endl;
}
};
class derived :public base
{
int n;
public:
derived(int a, int b) :base(a)
{
n = b;
}
};
void main()
{
derived obj(10, 18);
obj.base::show();
}