![](/img/trans.png)
[英]Object has type qualifiers that are not compatible with the member function
[英]the object has type qualifiers that are not compatible with the member function using vector
该示例生成错误
object 具有与成员 function 不兼容的类型限定符
我不知道为什么。
啊
class A {
public:
void f2(XXX* ..) const;
protected:
const vector<XYZ> f(){return m;}
vector<XYZ> m;
}
A.cpp
void A::f2(XXX* ..) const
{
const vector<XYZ>& P= this->f(); // Here I get this error as well
}
有人可以解释我做错了什么吗? 谢谢。
您不能从const
function 调用非常量 function。 这意味着f
也需要是const
限定的:
const std::vector<XYZ> f() const { return m; }
否则你不能从f2
调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.