抽象基类:
函数调用时,形参不能够是抽象基类,而应该是“指针”或者是"引用"。
// test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <cstdlib>
#include <new>
#include <iostream>
using namespace std;
class Base {
int a;
public:
virtual void x() const=0;
virtual int i() const=0;
};
class Derived : public Base{
public:
virtual void x() const {
cout<<"Derived x()"<<endl;
}
virtual int i() const {
cout<<"Derived i()"<<endl;
return 1;
}
};
void printd(Base& b)//如果使用Base将报错。
{
b.x();
b.i();
}
int _tmain(int argc, _TCHAR* argv[])
{
Derived de;
printd(de);
return 0;
}