When are temporary variables created by C++ compiler?

Author Topic: When are temporary variables created by C++ compiler?  (Read 443 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 159
  • Karma: 0
    • Hot Shaper
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

Quote
double 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

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


 

Related Topics

  Subject / Started by Replies Last post
1 Replies
2390 Views
Last post 01-21-2011, 02:11:52
by Home
1 Replies
871 Views
Last post 05-11-2016, 01:38:52
by TomClarke
0 Replies
534 Views
Last post 05-24-2016, 03:07:43
by chinmay.sahoo
0 Replies
153 Views
Last post 03-25-2017, 03:24:17
by beingchinmay