自考新教材-p266

抽象类示例

源程序:

#include <iostream>

using namespace std;

class A{

private:

int a;

public:

virtual void print()=0;

void func1(){

cout<<"func1"<<endl;

}

};

class B:public A{

public:

void print();

void func1(){

cout<<"B_func1"<<endl;

}

};

void B::print(){

cout<<"B_print"<<endl;

}

int main(){

//A a;

//A *p = new A;

//A b[2];

A *pa;

A *pb = new B;

pb->print();

B b;

A *pc = &b;

pc->func1();

return 0;

}

运行结果:

posted @ 2020-01-12 18:19  bobo哥  阅读(164)  评论(0编辑  收藏  举报