Quote:Original post by ehmdjii
it seems that the copy constructor is called here in the second line:
button b0, b1, b2, b3, b4, b5, b6, b7;button buttonArray[8] = {b0, b1, b2, b3, b4, b5, b6, b7};
why is that?
Because you are creating new instances of your button class in the array by copying the values in the array's initializer list.
It sounds like you are more familiar with the Java object model (in which all object instances are created on "the heap" and code only ever manipulates pointers to the instances) than the C++ object model, where object instances can be created in free store ("on the heap"), in automatic storage ("on the stack") or in static storage ("globals" or "statics").
Your code does not move the button instances into the array. It copies them. That means using the copy constructor (or, if the target is already constructed, the assignment operator).
So, make your copy constructor do the right thing. Then check your destructor to make sure it does the right thing (when is your texture freed?). Check that your assignment operator does the right thing. Learn the
rule of three.