I don't understand why we need a copy constructor (to begin with..) especially for the sake of reference members.
Given a class
class Foo {
Obj &obj;
};
I must now write a copy constructor and =
operator (and maybe 5 other secret things), otherwise it won't compile. Why? Why would a compiler be able to figure out that it should copy an int
or string
but not a reference? Same for a pointer? What does it think I might want to do instead? I have to write out exactly what the compiler writes out for every other property. What if I add, or worse, someone else adds, a new property to the class and forgets to add that to the copy ctor and operator?