The example generates the error
the object has type qualifiers that are not compatible with the member function
and I can't figure out why.
Ah
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
}
Can someone explain me what I've done wrong? Thanks.
You can't call a non-const function from a const
function. This means that f
needs to be const
qualified as well:
const std::vector<XYZ> f() const { return m; }
otherwise you can't call it from f2
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.