I have a class which allocates memory on the heap and then the destructor frees it. My copy constructor is never being called for some reason and I do not understand why. Here is my implementation:
AguiBitmap::AguiBitmap( const AguiBitmap &bmp )
{
this->nativeBitmapPtr = al_clone_bitmap(bmp.nativeBitmapPtr);
}
AguiBitmap::AguiBitmap( char *filename )
{
if(!filename)
{
nativeBitmapPtr = 0;
return;
}
nativeBitmapPtr = al_load_bitmap(filename);
if(nativeBitmapPtr)
{
width = al_get_bitmap_width(nativeBitmapPtr);
height = al_get_bitmap_height(nativeBitmapPtr);
}
else
{
width = 0;
height = 0;
}
}
ALLEGRO_BITMAP* AguiBitmap::getBitmap() const
{
return nativeBitmapPtr;
}
However, When I do something like:
AguiBitmap bitmap;
bitmap = AguiBitmap("somepath");
The copy constructor code is never called (set a breakpoint). And therefore, my issue of having an invalid pointer in the reconstructed object from the temporary object becomes invalid when the temporary one is destroyed.
What do I do to get my copy constructor to be called?
Thanks