#include <iostream>
#include <vector>
using namespace std;
class dog {
public:
dog() {}
dog(dog & d) {
}
};
int main() {
vector<dog> vec;
dog d;
vec.push_back(d);
return 0;
}
I can not insert dog into the vector. The problem lies in the copy constructor. If I add const in the copy constructor, the code compiles. I just wonder why I have to add const in the copy constructor.
The error message is:
error: binding ‘const dog’ to reference of type ‘dog&’ discards qualifiers