- 论坛徽章:
- 0
|
题目如下:
class A
{
public:
A()
{
cout << "A:A()" << endl;
init();
}
virtual ~A()
{
cout << "A:~A()" << endl;
}
virtual void init()
{
cout << "A:init()" << endl;
}
virtual void f()
{
cout << "A:f()" << endl;
}
};
class B:public A
{
public:
B()
{
cout << "B:B()" << endl;
}
~B()
{
cout << "B:~B()" << endl;
}
void init()
{
cout << "B:init()" << endl;
}
void f()
{
cout << "B:f()" << endl;
}
};
int main()
{
A *a = new B();
a->f();
delete a;
}
结果输出为:
A:A()
A:init()
B:B()
B:f()
B:~B()
A:~A()
其他的都好说,但是搞不懂为什么会输出A:init(),而不是B:init(),求解
|
|