If you like SEOmastering Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

When are temporary variables created by C++ compiler?

Started by chinmay.sahoo, 02-15-2016, 05:58:29

Previous topic - Next topic

chinmay.sahooTopic starter

Provided that function parameter is a "const reference", compiler generates temporary variable in following2 ways.

a) The actual argument is the correct type, but it isn't Lvalue

Quotedouble Cube(const double & num)
{
num = num * num * num;
return num;
}
double temp = 2.0;
double value = cube(3.0 + temp); // argument is a expression and not a Lvalue;

b) The actual argument is of the wrong type, but of a type that can be converted to the correct type

Quotelong temp = 3L;
double value = cuberoot ( temp); // long to double conversion



If you like SEOmastering Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...