64,642
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using std::cout;
using std::endl;
class Base
{
public:
Base(int para)
{
a = para;
cout << "Base::a = " << a << endl;
}
private:
int a;
};
class Derive : public Base
{
public:
int foo()
{
cout << "Derived::foo() return 0" << endl;
return 0;
}
Derive() : Base(foo()) {}
};
class Derive2 : public Base
{
public:
int foo()
{
cout << "Derive2::foo() return " << a << endl;
return a;
}
Derive2() : a(0), Base(foo()) {}
private:
int a;
};
int main(void)
{
Derive cld;
Derive2 cld2;
//Base *bptr = new Derive;
//bptr->foo(); //error: Base has no member named foo
return 0;
}