assignment of class with const member
问题 Consider the following code: struct s { const int id; s(int _id): id(_id) {} }; // ... vector<s> v; v.push_back(s(1)); I get a compiler error that 'const int id' cannot use default assignment operator. Q1. Why does push_back() need an assignment operator? A1. Because the current c++ standard says so. Q2. What should I do? I don't want to give up the const specifier I want the data to be copied A2. I will use smart pointers. Q3. I came up with a "solution", which seems rather insane: s&