Please do not presume to know how I go about my coding. Part of the design process (before coding starts) is to determine whether copying is a valid operation for the class. If it is not, then the copy ctor and copy assignment operator are declared private. This way, contrary to what you presume, the compiler most definitely will tell me if I attempt to make a copy. On the other hand, if the initial design says that copying is valid, then any modification to the members of the class necessitates a review of the copy ctor/copy assign (and destructor and default ctor).Quote:
Originally posted by AnthonyMai
The problem is you may FORGET! There are a lot of things that will cause you to forget to write the copy constructor or assignment constructor. And nothing in the compiler will remind you that you missed something. Maybe you initially don't need one, and later you modified something and you need to add one on, but you forget. It's a quite possible scenary.
The problem is, if you see a line of your own code where you assign one object to another, you might remind yourself to check
to make sure you coded the assignment operator. But if you don't do any copying and assigning yourself, what would remind you to make sure that you have provided every thing to baby-sit the ATL underneath, which doesn't even cry when you missed something?
No, I don't code an assignment, then make a note to check the assignment operator - the decision has been made. If I (erroneously) code an assignment for a class that can't be assigned, then the compiler will throw out an error, and I can review the situation. However, since my classes tend to be well designed, this is rarely an issue, since the decision to disable copying usually implies that there will never be a need to copy, so I probably wouldn't even consider trying to assign one to another.
Your reply suggests that you take a very piecemeal approach to coding, trying things to see if they work, tweaking here and there, making up the design as you go. I take a somewhat different approach - my classes are designed with an end in mind, that means that most of the major decisions have been made before Visual Studio has even been fired up.
In short: No, I won't forget about such important things, and I make sure that if I accidentally do something that I've determined isn't allowed, then the compiler will tell me that I've done something wrong.
