c++虚函数调用及使用

#include <iostream>
using namespace std;
class A
{
public:
        virtual int print()=0;
};
class B: public A
{
public:
        virtual int get()=0;
        virtual int print()
        {
                cout<<get()<<endl;
        }
};
class C: public B
{
public:
        int get()
        {
                return 100;
        }
};
int func(A* a)
{
        a->print();
}
int main()
{
        C c;
        func(&c);
        return 0;
}              

 

posted on 2016-11-10 15:35  川洋  阅读(217)  评论(0编辑  收藏  举报