I am stuck with using immutable objects with collections. Let assume I have the following class :
//in .h
class Data {
public:
Data(const DataObj& data);
Data(const Data&);
const DataObj& getDataObj() const;
private:
const DataObj _data; //actually several objects or simple type
}
inline const DataObj& Data::getDataObj() const {return _data};
//in .c
Data(const DataObj& data) : _data(data){};
Data(const Data& original) : _data(original._data){}
The issue is that when I want to use collections, I have the error
in member function Data&Data::operator(const Data&);
instantiation from 'typename QMap<Key,T>::iterator QMap<Key, T>::insert(const Key&, const T&)[with Key = int, T = Data]'
instantiation from here
error : non-static const member 'const DataObj Data::_data', can't use default assignment operator
Now defining an assignment operator doesn't seems to make sense, since its prototype will be
Data& operator=(const Data&);
What should I do? Am I forced to remove all constant qualifiers in order to use my class inside collections? Or use pointers?