![](/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.