Actually, I don't know why, but the NRVO is finally working.
Last thing and this topic will be marked as solved.
My move assignment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
GString& GString::operator=(GString&& other)
{
std::cout << "MOVE ASSIGNMENT OPERATOR" << " " << this->mainString
// Here we can't use the Create() function, because it would be inefficient in this case
this->Clear();
size = other.size;
mainString = other.mainString;
other.size = 0;
other.mainString = nullptr;
return *this;
}
The main()
1 2 3 4 5 6 7
int main()
{
GString h = "hello";
// this calls the MOVE ASSIGNMENT
h = "hello2";
}
Note that I have another operator= overload which takes a const GString& as argument.
What I would like to know is if I correctly understood what's going on:
1. "hello2" is implicitly converted to a GString object (since there IS a constructor which takes a const char* as argument)
2. The newly created temporary is assigned using the Move Semantics.