c++ const

来源:百度知道 编辑:UC知道 时间:2024/06/18 17:48:48
const int & top() const
{if(empty()) return *buffer;
else ruturn *(sp-1);
}
把第二个const去掉后运行,就出错了,为什么啊??

你这应该是一个类的成员函数吧,你把调用它的代码写出来看看。

我估计是一个被声明为const的对象,然后你调用它的这个方法,那肯定要求这个方法有const修饰符了。

程序太短,看不出原因来。