请教:关于类中的mutable数据成员

wengchaohui wengchaohui 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在书本上看到一个例子,
int getcurrent();
class a
{public:
bool s()const;

private:
mutable int y;
};
bool a::s()const
{y=getcurrent();
return 0;
}
如上,一切正常,可是为什么将上面改为
class a
{public:
bool s()const;
int getcurrent();
private:
mutable int y;
};
bool a::s()const
{y=getcurrent();
return 0;
}
就不行了(就是把int getcurrent();从类外面改为类里面,)提示的错误信息是这样的
: error C2662: 'getcurrent' : cannot convert 'this' pointer from 'const class a' to 'class a &'
再一次麻烦各位了,,,
...全文
评论 3
收藏 已收藏
分享
返回顶部
wengchaohui
C++ 语言 65,214 成员 250,514 内容