c ++ const reference generating initial value must be lvalue

This occurs because the call type parameter is a function of T & (T for a particular type), the type of call parameter values ​​passed are inconsistent, such as the function parameter is an int, the incoming arguments are double, the presence of implicit type conversions, the system will automatically generate the temporary variable temp constants were modified.

 

 

The solution, to avoid an implicit call, such as: int y = 5; double x = (double) y, and then x value passed to the function

2. In the parameter before adding const, avoiding modify parameters.

Guess you like

Origin www.cnblogs.com/sozze011/p/11257281.html