重载与const
来源:互联网 发布:win7 64位c语言编译器 编辑:程序博客网 时间:2024/05/22 00:26
#ifndef _OVERLOAD_TEST_H_
#define _OVERLOAD_TEST_H_
class COverloadTest
{
public:
COverloadTest() : m_nValue(0) {}
~COverloadTest() {}
public:
const int getValue() const
{
cout << "const getValue" << endl;
return m_nValue;
}
int getValue()
{
cout << "getValue" << endl;
return m_nValue;
}
private:
int m_nValue;
};
#endif
调用:
COverloadTest test;
const int value = test.getValue();
上述代码可以编译通过,但是在执行时是调用的非const类型的成员函数。
输出为:
getValue
- 重载与const
- const与重载
- const 与重载
- const 与重载
- const与重载函数
- const与重载
- const 与重载
- C++ const 与 重载
- const 与重载
- [C++] const与重载
- const与重载
- const&volatile 与函数重载
- const 参数重载与const 成员函数重载
- 顶层const、底层const、函数重载与const形参
- const型变量与函数重载
- const型变量与函数重载
- const型变量与函数重载
- 关于const与函数重载问题
- DOS命令全集(2)
- 空虚
- 查询借出次数超过2次的所有图书的书号和书名;
- SQL语句
- 贪心算法[转自王晓东《算法设计与分析》一书]
- 重载与const
- Windows, Ubuntu双系统安装
- Symbian中HBufC的使用
- 头脑风暴:自愿广告平台
- PHP5.0/6.PEARのインストール
- Symbian中TBuf初始化汉字为乱码的解决方法
- 加油学习c 语言
- where 和 having 怎么区别
- Ubuntu下JDK安装配置