0

X is a class

X operator+()
{
X a;
return a;
}

Book iam reading(ivor horton C++)says that when this function is called and the move constructor has been implemented for the class 'X' ,class constructor and move constructor are called. if the move constructor isn't implemented, constructor and copy constructor are called

i feel that because object 'a' is a lvalue copy constructor should be called all the time. move constructor has rvalue reference as parameter so an lvalue can't be passed to it.

can anyone explain why the move construcor is called.

  • 1
    does this one answer your question? http://stackoverflow.com/questions/13618506/is-it-possible-to-stdmove-objects-out-of-functions-c11/13618587#13618587 – billz Jun 20 '13 at 11:59
  • @billz so if the object has both move and copy constructors defined compiler chooses move? – long_claw Jun 20 '13 at 12:11
  • The answer does include this step particular part. :) – billz Jun 20 '13 at 12:17

0 Answers0