首页 > 其他 > 详细

void out2() const{

时间:2020-06-09 11:19:49      阅读:44      评论:0      收藏:0      [点我收藏+]

include "stdafx.h"

include

using namespace std;

class aa{
int num;
public:
aa(){
int b =10;
num = b;
};
void out1(){
cout<<num<<endl;
}
void out2() const{
cout<<num<<endl;
}
void out3() const{
num+=10; //出错,const函数不能修改其数据成员
cout<<num<<endl;
}

};
int _tmain(int argc, _TCHAR* argv[])
{
aa a1;
a1.out1();
a1.out2();
a1.out3();
const aa a2;
a2.out1(); // 错误,const的成员 不能访问非const的函数
a2.out2();
a2.out3();
return 0;
}

void out2() const{

原文:https://www.cnblogs.com/DXGG-Bond/p/13071294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!