#include <iostream>
using namespace std; class Test {
public:
int x;
int y;
void const_m1() const;
void const_m2() const;
void m3();
void m4();
};
/**
* //1常成员函数不能修改成员变量的值
* //2常成员函数只能调用常成员函数,不能调用普通成员函数
* //3普通成员函数可以调用常成员函数
*/
void Test::const_m1(void)const {
cout<<"start of const_m1() ,call:"<<endl;
this->const_m2();//可以调用const_m2()
//this->m3();//error C2662: “Test::m3”: 不能将“this”指针从“const Test”转换为“Test &”
//this->m4();//error C2662: “Test::m4”: 不能将“this”指针从“const Test”转换为“Test &”
//this->x = 3;//error C3490: 由于正在通过常量对象访问“x”,因此无法对其进行修改
cout<<"end of const_m1()"<<endl;
}
void Test::const_m2(void)const {
cout<<"this is const_m2()"<<endl;
}
void Test::m3(void) {
cout<<"this is m3(),call:"<<endl;
this->const_m2();
cout<<"end of m3()"<<endl;
}
void Test::m4(void) {
cout<<"this is m4()"<<endl;
this->x = ;
} int main(void) {
Test demo;
demo.const_m1();
demo.const_m2();
demo.m3();
demo.m4();
while();
return ;
}

/*测试结果:
start of const_m1() ,call:
this is const_m2()
end of const_m1()
this is const_m2()
this is m3(),call:
this is const_m2()
end of m3()
this is m4()
*/


最新文章

  1. Fiddler (三) Composer创建和发送HTTP Request
  2. Codevs 1051 二叉树最大宽度和高度
  3. jquery.form.js详细讲解
  4. ren
  5. This version of MySQL doesn’t yet support ‘LIMIT &amp; IN/ALL/ANY/SOME 错误解决
  6. jsp 是什么 ,jsp 隐式对象
  7. CentOS 6.6安装LAMP和Subversion服务器
  8. 协议Protocol
  9. c#基础精华01(强调代码规范,虚方法,抽象方法,接口)
  10. 可恶的QT隐式共享
  11. 完全不借助VS,编写C#控制台应用程序
  12. SQL Server常用脚本
  13. java list基本用法
  14. java多线程——同步块synchronized详解
  15. USACO Ski Course Design 暴力
  16. php+redis 学习 四 队列
  17. unittest测试用例的执行顺序
  18. Windows下安装Python虚拟环境
  19. C#中用DateTime的ParseExact方法解析日期时间(excel中使用系统默认的日期格式)
  20. Spring实战拆书--SpringBean

热门文章

  1. gcc 的编译过程
  2. BZOJ 1878: [SDOI2009]HH的项链( BIT )
  3. BZOJ 1044: [HAOI2008]木棍分割(二分答案 + dp)
  4. Servlet url-pattern优先级
  5. php 计算多维数组中所有值的总和
  6. Centos 安装docker报错
  7. 调不尽的内存泄漏,用不完的Valgrind
  8. Delphi 类型转换函数(有几个函数没见过,FloatToStrF,FloatToText等等)
  9. poj 1386 Play on Words(有向图欧拉路+并查集)
  10. Node.cluster