文章教程

C++ 中const修饰虚函数实例详解

5/9/2018 9:58:11 PM 人评论 次浏览

C++ 中const修饰虚函数实例详解

【1】程序1

#include <iostream>
using namespace std;

class Base
{
public:
 virtual void print() const = 0;
};

class Test : public Base
{
public:
 void print();
};

void Test::print()
{
 cout << "Test::print()" << endl;
}

void main()
{
 // Base* pChild = new Test(); //compile error!
 // pChild->print();
}