I'm trying to test my copy con and move con as well as their assignment operators. It NEVER gets invoked :S Copy con gets invoked just fine but the assignment operators are never called and neither is the move constructor. How can I test it to make sure it works just right? I've read a TON of tutorials on it to make sure I got everything down to the very last detail but now when it's time to test it, only the copy con is invoked. It doesn't actually load or save a bitmap. It's just a class I called that and put a vector member of a struct so I don't have to use pointers for now.. (Defined as vector<BYTE> Pixels). No implementation, just bare testing.
I just don't want under the hood problems or future problems. It's just a class I created specifically for learning Copy/Move/Swap semantics but I never know if I'll need it.
I'm testing with:
Bitmaps A = Bitmaps("C:/Meh.bmp");
Bitmaps B(Bitmaps("C:/Meh.bmp"));
Bitmaps C = A;
//I'll write code to test if change on one data member affects that of another object later.
And implementing with:
//Just a huge initiaization list. Copy Constructor:
Bitmaps::Bitmaps(const Bitmaps& Bmp) : Pixels(Bmp.Pixels), Info(Bmp.Info), width(Bmp.width), height(Bmp.height), size(Bmp.size), bFileHeader(Bmp.bFileHeader), TransparentColor(Rgb(0)), DC(0), Image(0){std::cout<<"Copy Constructor Called.\n"}
//Just a huge initialization list. Move Constructor:
Bitmaps::Bitmaps(Bitmaps&& Bmp) : Pixels(0), Info(), width(Bmp.width), height(Bmp.height), size(Bmp.size), bFileHeader(), TransparentColor(Rgb(0)), DC(0), Image(0)
{
std::cout<<"Move Constructor Called.\n"
this->Swap(Bmp);
Bmp.Pixels.clear(); //A vector.
}
Bitmaps& Bitmaps::operator = (Bitmaps Bmp) //Pass by value.
{
std::cout<<"Copy Assignment Called.\n"
Bmp.Swap(*this);
return *this;
}
Bitmaps& Bitmaps::operator = (Bitmaps&& Bmp)
{
std::cout<<"Move Assignment Called.\n"
Bmp.Swap(*this);
return *this;
}
void Bitmaps::Swap(Bitmaps& Bmp) //throw()
{
std::swap(Pixels, Bmp.Pixels); //Vector.
std::swap(Info, Bmp.Info); //BmpInfoheader.
std::swap(width, Bmp.width);
std::swap(height, Bmp.height);
std::swap(size, Bmp.size);
std::swap(bFileHeader, Bmp.bFileHeader); //BmpFileHeader.
std::swap(Image, Bmp.Image); //HBitmap.
std::swap(DC, Bmp.DC); //HDC.
}
The only thing that ever prints is: "Copy Contructor called.". Not even the assignment operator is called. I even tried making it RValue by doing operator = (const Bitmaps& BMP)
Is there some magic happening that I cannot see? Or am I just testing it or implementing it wrong? I read that RVO can cause such behaviour but I have my doubts in my implementation since it's my first time actually trying and testing my copy/move/swap stuff.