Original Post
class trzGUI
{
public:
explicit trzGUI();
virtual ~trzGUI();
private:
//Prevent illegal copying or assignments
trzGUI(const trzGUI &gui);
trzGUI &operator=(const trzGUI &gui);
};
This is a class template I have. All my class are created with these constructors and a destructor. I have a few queries.
They say the explicit keyword is compiler specific. It prevents assignments during initilisation eg.
trzGUI gui = anotherGUI;I've read in another article somewhere that another way to prevent this is to put the copy constructor and overloaded assignment operator in private. For extra measure I just include both ways, realising that somehow (though not exactly sure how) I've overlapped these two method's results. However, I do realise that putting the assignment operator in private prevents assigning it to anything. What can I remove without taking away the preventive benefits provided? Also, are there any side effects that can be caused if this is done? I haven't encountered any problems thus far though. Just a thought since I've been programming this way since starting on my project. =p [edited by - Darkor on November 21, 2003 11:51:00 AM]