We're working with RVO in class to show how we can reduce the number of temporaries created.
I get the basics of it but I'm having difficulty understanding how to combine multiple values to return into one line.
For single temp optimization I was able to understand it fairly easy
const A operator + ( const A &tmp)
{
A sum;
sum = this->x + tmp.x;
return sum;
}
can be reduced to:
const A operator + ( const A &tmp)
{
return A(this->x + tmp.x);
}
However I'm uncertain how to apply this to a function with multiple values to return. For example:
Vect2D operator - ( const Vect2D &tmp ) const;
Vect2D Vect2D::operator - ( const Vect2D &tmp ) const
{
Vect2D sum;
sum.x = this->x - tmp.x;
sum.y = this->y - tmp.y;
return ( sum );
};
My process behind it would be:
Vect2D Vect2D::operator - ( const Vect2D &tmp ) const
{
return Vect2D((this->x - tmp.x), (this->y - tmp.y));
};
which comes back with an error telling me "no argument takes the value (float, float)
".
would I have to reorganize the initial
Vect2D operator - ( const Vect2D &tmp ) const;
to take two float arguments within? or am I thinking about this in the wrong way?
Thank you,
E: Thanks to Matt and Jerry for affirming what I thought I needed to do with the double float operator.