Some language constructs require a copy constructor:
- transmission by value
- return by value
- Initializing the copy style (although a copy is often copied in this case)
If the language calls the copy, and you provided the copy constructor, then it can be used (provided that the cv-qualifications are in order, of course).
Since you did not provide a copy constructor, you will get a copy constructor created by the compiler instead. This works by copying each data item, even if it is not suitable for your class. For example, if your not-a-copy constructor explicitly makes any deep copies or allocates resources, you need to suppress the copy generated by the compiler.
If the copy created by the compiler works for your class, then your non-copy constructor is basically harmless. I do not think this is a particularly good idea:
void some_function(const MyClass &foo); MyClass *ptr = new MyClass(); const MyClass *ptr2 = ptr; some_function(ptr);
Even assuming that the copy created by the compiler is not suitable for your class, a lot of refactoring is not required to make the necessary changes. Suppose your non-constructor does not actually modify the object that its argument points to, so after correcting your signature:
MyClass::MyClass(const MyClass* my_class) {
You need:
MyClass::MyClass(const MyClass& my_class) { do_stuff(my_class); } MyClass::MyClass(const MyClass* my_class) { // maybe treat null pointer specially do_stuff(*my_class); } MyClass::do_stuff(const MyClass& my_class) { // do stuff here }
You also need to copy any initializer list from the old constructor to the new one and change it so that my_class not a pointer to the new one.
Removing the old constructor may require a lot of refactoring, since you need to edit any code that uses it. However, you do not need to remove the old constructor to fix any problems with the default copy constructor.