I have code like this:
class Pair{
public:
Pair(Pair && other){};
Pair(Pair & other){};
};
class IROList{
public:
virtual const Pair get(const char *key) const = 0;
inline const Pair operator[](const char *key) const{
return this->get(key);
// error: binding ‘const Pair’ to reference of type ‘Pair&&’ discards qualifiers
}
};
when compiled, it produce
error: binding ‘const Pair’ to reference of type ‘Pair&&’ discards qualifiers
if I change move constructor to const, error dissipated.
Pair(const Pair && other){};
However, if move constructor takes const, I can not really move the data. I should copy it.
Is there any workaround except removing the const of returning methods, e.g.
virtual Pair get(const char *key) const = 0;
inline Pair operator[](const char *key) const;