当前位置: 首页 > 文章教程  > 计算机与互联网 > 网络编程

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()" << e…

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();
}

相关教程

共有条评论 网友评论

验证码: 看不清楚?