Call Constructor from Copy Constructor -> Stack Overflow

Pages: 123
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.

PS: Copy elision is ON, compiled with VC++
Last edited on
Wasn't this discussed earlier? http://www.cplusplus.com/forum/general/191860/2/#msg925637

The only difference being that now there is a move assignment operator, and that would be selected because the anonymous temporary is an rvalue.

http://coliru.stacked-crooked.com/a/12267a643352554f
http://rextester.com/ZYC34872
Topic archived. No new replies allowed.
Pages: 123