I searched, but cannot find the answer to “When,” to use them. I just keep hearing that it’s good, because it saves me an extra copy. I went around it in every class that I had, but some, as it did not look for some classes: S I read countless tutorials on LValues and RValues and std :: move vs. std :: copy vs. memcpy vs. memmove etc. And even read on throw (), but I'm not sure when to use this.
My code looks like this:
struct Point
{
int X, Y;
Point();
Point(int x, int y);
~Point();
};
Then I have an array of classes similar to (RAII sorta thing):
class PA
{
private:
std::vector<Point> PointsList;
public:
PA();
~PA();
};
? Point Class, , . PA, , , . , , :
BMPS::BMPS(const BMPS& Bmp) : Bytes(((Bmp.width * Bmp.height) != 0) ? new RGB[Bmp.width * Bmp.height] : nullptr), width(Bmp.width), height(Bmp.height), size(Bmp.size), DC(0), Image(0)
{
std::copy(Bmp.Bytes, Bmp.Bytes + (width * height), Bytes);
BMInfo = Bmp.BMInfo;
bFHeader = Bmp.bFHeader;
}
BMPS::BMPS(BMPS&& Bmp) : Bytes(nullptr), width(Bmp.width), height(Bmp.height), size(Bmp.size), DC(0), Image(0)
{
Bmp.Swap(*this);
Bmp.Bytes = nullptr;
}
BMPS& BMPS::operator = (BMPS Bmp)
{
Bmp.Swap(*this);
return *this;
}
BMPS& BMPS::operator = (BMPS&& Bmp)
{
this->Swap(Bmp);
return *this;
}
void BMPS::Swap(BMPS& Bmp)
{
std::swap(Bytes, Bmp.Bytes);
std::swap(BMInfo, Bmp.BMInfo);
std::swap(width, Bmp.width);
std::swap(height, Bmp.height);
std::swap(size, Bmp.size);
std::swap(bFHeader, Bmp.bFHeader);
}
? - ? ()? ? ? Ahh : c , , , . , unique_ptr Bytes? ( /.)