When it comes to the copy, move, and assignment operators of a child class how is it supposed to look?
If this is the implementation of my parent class
//Default constructor
Buffer::Buffer()
{
buffer = nullptr;
}
//Copy constructor
Buffer::Buffer(const Buffer& other)
{
buffer = other.buffer;
buffer->AddRef();
}
//Move constructor
Buffer::Buffer(Buffer&& other)
{
buffer = other.buffer;
buffer->AddRef();
other.release(); //Free the buffer resource of the other instance
}
//Destructor
Buffer::~Buffer()
{
release();
}
//Copy assignment
Buffer& Buffer::operator=(const Buffer& other)
{
if (&other != this)
{
release(); //Free the buffer of this instance
buffer = other.buffer;
buffer->AddRef();
}
return *this;
}
//Move assignment
Buffer& Buffer::operator=(Buffer&& other)
{
if (&other != this)
{
release(); //Free the buffer of this instance
buffer = other.buffer;
buffer->AddRef();
other.release(); //Free the buffer of the other instance
}
return *this;
}
And this is the implementation of my child class. Is this correct?
I'm really just wondering about the at the copy, move, and I'm not too sure about the assignment operators
//Default constructor
VertexBuffer::VertexBuffer() : Buffer()
{
}
//Copt constructor
VertexBuffer::VertexBuffer(const VertexBuffer& other) : Buffer(other)
{
}
//Move constructor
VertexBuffer::VertexBuffer(VertexBuffer&& other) : Buffer(other)
{
}
//Destructor
VertexBuffer::~VertexBuffer()
{
}
//Not sure how to handle the copy/move operators.
//Do I treat them as there own operators and copy the Buffer assignment operators code?
VertexBuffer& VertexBuffer::operator=(const VertexBuffer& other)
{
}
VertexBuffer& VertexBuffer::operator=(VertexBuffer&& other)
{
}