About 11 months ago I started this thread asking why I couldn't use a const data member in a class that was going to be used in an stl container. The explanations were excellent.
Now my question is, what is the best alternative to having a class with BOTH
a) const data members and
b) an assignment operator (necessary for stl containers)?
As far as I can tell, the main reason to declare a data member as const is to remind the user of that class not to change it's value.
My current solution is to use a pointer to a const object that lives in a more global scope. While the pointer itself is not constant, at least the underlying object is const. Now I'm wondering if there is a better way.
I've found threads that used casting in the assignment operator to copy const data members (seems like a bad idea), and yet another that suggested avoiding the assignemt operator all together by using
vector<shared_ptr<myObj>> instead of
vector<myObj> for instance (seems like a pretty good idea).
Which would generally be the best solution or is it a case by case kind of thing?