记一道C++的笔试基础题,当时都有点拿不准,回来验证了下还是对了,通过面试,学习不断巩固吧,
也不可能现在抱着C++的书看了。。。
#include<stdio.h>
#include<iostream>
using namespace std;
class A{
public:
A(){DoSomething();}
virtual void DoSomething(){cout << "I am A" << endl;}
};
class B:public A
{
public:
virtual void DoSomething(){cout << "I am B" << endl;}
};
int main()
{
B b;
b.DoSomething();
A *pA = new B;
pA->DoSomething();
return 0;
}
// The result: A B A B