标签:ring name cti 实例化 comment clu 纯虚函数 ams span
#include <iostream>
using namespace std;
class A{
public:
virtual void eat() = 0;
virtual void sleep() = 0;
};
int main(){
//编译不过
//A a;//抽象类不可以被实例化
A *a;//但是可以定义抽象类的指针
}
#include <iostream>
using namespace std;
class A{
public:
virtual void eat() = 0;
virtual void sleep() = 0;
void fly(){
eat();
}
};
class Human : public A{
public:
virtual void eat(){
cout << "human eat" << endl;
}
virtual void sleep(){
cout << "human sleep" << endl;
}
};
int main(){
Human p;
A *a = &p;
a->fly();
}
标签:ring name cti 实例化 comment clu 纯虚函数 ams span
原文地址:https://www.cnblogs.com/guojun/p/9723693.html