I’m new to move constructor and quite confused with VS2010 behavior.
I design a move constructor (of class A) which in my knowledge is like this:
A(A&& input) {some code}
When I use list’s emplace and put an instance of class A:
mylist.emplace(a);
My move constructor is not called, and a non-const copy constructor is called instead:
A(A& input) {the same code as move constructor}
On the other hand when I do this:
mylist.emplace(A(2));
My move constructor is called like it supposed to. So, my question is:
- Why is list’s emplace call my non-const copy constructor instead of my move constructor?
- Is the non-const copy constructor is actually an alternative way to define a move constructor?
- Is this behavior is correct (for a c++0x compiler) or it just VS2010’s behavior?
Thanks a bunch in advance.
Here
ais an l-value, hence it’s copied rather than moved. You need tomoveit explicitely:Yes, the behavior is correct.