query about the movement constructor

0

Let's see if you can indicate that I do not see.

In my code I have a function of type, as a test function.

   Rational f(Rational o){ return o;}

and in the main I have asinanción:

   Rational a(3,5);
   Rational c= f(a);

The object returned by f in the return is a temporary object, it is a rvalue, then the movement constructor is called, c did not exist. So far, everything behaves according to what I expected.

But if I define a function of the type:

   Rational f(Rational & rhs){
       return Rational(rhs.numerator(),rhs.denominator());
  }

If now in the main I do, the same as before. The motion constructor is not being called. is constructed in the body of f, the temporary object with no name, calling the constructor, Rational (int &, int &), but nothing is called in the assignment. Does anyone know where the shots can go?

    
asked by Jcpardo 16.05.2018 в 21:48
source

0 answers