Can I write different copyCtor for const and non-const instances?
问题 I have the following problem: I have a class which should do this: Obj o; Obj o1(o), o1=o; // deep-copies const Obj c(o), c=o; // deep-copies const Obj c1(c), c1=c; // shallow-copies Obj o2(c), o2=c; // deep-copies How can I do this preferably without inheritance? (I mean I would do Const_obj inheriting from Obj otherwise.) EDIT: Using o.clone() directly is not an option because then I could easily introduce bugs by accidentally not cloning. EDIT: Finally, there is a proper, complete solution