In writing a copy constructor for one of my classes ( which holds a few objects of other UDTs ), I am required to create a default constructor for those UDTs, even though they were never really meant to have one.
Is it fine to just implement a blank default constructor and be done with it? The only time the default constructor is invoked is during this copying, when the object is created and then the values of the corresponding object are copied to it. Thus, whatever values are assigned to the object in the default constructor will never actually be used.
The problem I see is that some member variables aren’t initialized in a blank default constructor. Should I just write one that gives dummy values instead? Any other recommended ways to handle this?
Edit: I understand that a copy constructor doesn’t NEED a default constructor if I were to define copy constructors for the other classes, but I didn’t, so it does need it.
If you use an initializer list in the copy constructor, you don’t need a default constructor:
Results in: