const stock& compare(const stock& s)const
其中stock是一个类
请问最后一个const代表什么意思?
表示这个函数不允许修改对象实例。
比如
class A
{
private: int x;
public void foo() const
{
this.x = 123; // error
}
public void bar()
{
this.x = 456; // ok
}
}
楼上的语法是有错误的:this是一个指针,不是结构之类的,所以访问成员函数要用:
(*this).x 或者 this->x
this指针可以参考博客:
http://blog.csdn.net/qq_35644234/article/details/52623570