其中抽象类指的是在类的定义中出现了纯虚函数,导致无法实例化,。

代码:头文件

#include "stdafx.h"

using namespace std;

class Person{
public:
Person();
~Person();

virtual void work() = 0;
};

//Coder 继承Person
class Coder : public Person
{
public:
Coder();
~Coder();
virtual void work();
};

实现CPP文件

// AbstractDemo.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "PersonDemo.h"

using namespace std;

Person::Person()
{
cout <<"测试创建" << endl;
}

Person::~Person()
{
cout << "End" << endl;

}

//void Person::work()
//{
//cout << "I am working" << endl;
//}

Coder::Coder()
{
cout << "Coder Created." << endl;
}

Coder::~Coder()
{
cout << "Clear";
}

void Coder::work()
{
cout << "996"<< endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
Coder *mm = new Coder();
mm->work();
int d ;
cin >> d;
return 0;
}