簡體   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