Closed Fox32 closed 12 years ago
An implementation for a move constructor could be:
VertexArray::VertexArray( VertexArray&& other ) { this->id = other.id; glGenVertexArrays( 1, &other.id ); }
And for a move assingment:
VertexArray& VertexArray::operator=( VertexArray&& other ) { if (this != &other) { glDeleteVertexArrays( 1, &this->id ); this->id = other.id; glGenVertexArrays( 1, &other.id ); } return *this; }
The problem is that a VertexArray can't be empty. We have to create a new VertexArray after each move. Another way would be allowing an empty VertexArray (id=0) and checks if the VertexArray is empty. But this would result in more code for all the check for empty objects.
Hiding the copy constructor and assignment operator stops developers from setting types into undefined states. They can still use pointers or smart pointers to pass the types (like storing textures in a vector/map). It would probably make sense to implement to C++11 move constructor to allow moving the ownership of data between objects. Like moving the texture id from one to another object and leaving an empty object. But this need to be in an #if for non C++11 compilers.
Passing by const reference doesn't make sense for enums