Hello, I use CodeBlocks/MingW32 on Windows XP. I turned on the "allow effective c++ warnings (thanks Scott Meyers) option in the compiler/linker options menu, and the result was this:
warning: 'class SoundEffects' has pointer data members
warning: but does not override 'SoundEffects(const SoundEffects&)
warning: or 'operator=(const SoundEffects&)'
This SoundEffects class is a stand-alone basic class, with no children or parents and no const member functions as it isn't passed by constant reference (yet), so I'm wondering what the method is to satisfy the effective c++ warning in this instance. Any and all responses welcome, and thanks in advance! -B
if you don't declare a copy constructor or operator= in a class then the compiler will make one for you in which it just uses operator= on all data members.
You have pointer data members, if you use the standard operator= on pointers it just makes that pointer point towards the same data as the variable on the right hand side of the operator, so you would end up with several objects which all use the same memory, and if you delete one of these objects it will delete the data pointed to by the pointer data members in that object, which other objects need.
Declare your own operator== and copy constructors which allocate new data then copy the contents over, giving each object of that type its own seperate memory for the pointer members.
I hope this was clear...I don't think I explained it very well.
In other words, the synthesized copy constructor calls the copy constructors of all data members; the synthesized operator= calls the operator= of all data members.
[Edit:] Warning: if you have copy constructor only, but no operator=, the automatic operator= will be synthesized for you. Also, if you have operator=, but no copy constructor, the copy constructor will be synthesized for you (rather than use the operator=). To check that, simply comment out the operator= of theDataEntry.