W8028 Temporary used to initialize 'identifier' (C++)

From RAD Studio
Jump to: navigation, search

Go Up to Compiler Errors And Warnings (C++) Index


Command-line option to suppress warning:

-w-lin

In C++, a variable or parameter of reference type must be assigned a reference to an object of the same type.

If the types do not match, the actual value is assigned to a temporary of the correct type, and the address of the temporary is assigned to the reference variable or parameter.

The warning means that the reference variable or parameter does not refer to what you expect, but to a temporary variable, otherwise unused.

Example

In this example, function f requires a reference to an int, and c is a char:

f(int&);

// ...

  char c;
  f(c);

Instead of calling f with the address of c, the compiler generates code equivalent to the C++ source code:

int x = c;
f(x);