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 with lazy evaluation using the idea from Effective C++ by Scott Meyers. Check out my answer below.
No, you can't.
Also, if it was possible, I would find it really confusing. Just make methods that suit your needs, and name them in an unambiguous way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With