Essential C++的小问题

ml457 2002-03-17 03:26:13
<<Essential C++>> 4.3何谓mutable和const中讲到(P110):
虽然编译器不会为每个函数进行分析,决定它究竟是const还是non-const,但它会检查每个声明为const的member function,看看他们是否真的没有更动class object....
bool Triangular::next(int &value) const
{
if(_next<_beg_pos+_length-1)
{
//错误:更动了_next之值
value=_elems[_next++];
return true;
}
return false;
}
不明白,为什么更动了_next的值,就算更动了class object内容。
程序段中的_next可是_elems的下标呀???
请大家指教。
...全文
26 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
allofeagle 2002-03-17
  • 打赏
  • 举报
回复
but the value _next is the member variant of the class,just the member of the class is changed in the function ,that will go wrong!

1,650

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 非技术类
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧