I tried to have a struct with copy assignment, but it gave me some error.
struct Data {
unsigned short xx;
unsigned short yy;
std::map<int, vector<int>> map;
bool operator<(....& rhs) const
{
......
}
bool operator==(....& rhs) const
{
return xx == rhs.xx && yy == rhs.yy;
}
Data& operator=(const Data& rhs) {
if (this != &rhs) {
xx = rhs.xx;
yy = rhs.yy;
for (int i = 0; i < 20; i++){
vector<int> temp;
vector<int> tempC = rhs.map[i];
for (int j = 0; j < tempC.size(); j++){
temp.push_back(tempC[j]);
}
map[i] = temp;
}
}
return *this;
}
};
Error message:
Error: passing 'const std::map<int, std::vector<int> >' as 'this' argument discards qualifiers [-fpermissive]
so what is wrong?