繁体   English   中英

object 的类型限定符与使用向量的成员 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM