Project scenario:
The error information reported during project code compilation is as follows:
error: non-const lvalue reference to type '...' cannot bind to a value of unrelated type '...'
Problem Description:
After the project problem is simply abstracted, it is equivalent to the following problems:
Do this and compile through
int a;
const double& m = a;
However, an error is reported in this compilation
int a;
double& m = a;
Error information such as title
Cause analysis:
Because temporary variables cannot be bound to a non const reference
double& m = a;
a
is an int variable that will be implicitly converted to a double variable, so this process generates a temporary variable. Non const reference cannot bind temporary variables
Solution:
Avoid implicit conversion or add const
Read More:
- Android:Field can be converted to a local varible.
- Error: global variable is ambiguous (conflict between using namespace STD and global variable)
- Use of C + + ifstream and error handling
- Various errors (c + +)
- main.cpp : (. Text + 0xd06): undefined reference to XX method | simple record
- About the cause of the long-standing ADO error: unspecified error “(error code = 0x80004005) (excerpt from the Internet)
- Cmake[Warning]:Policy CMP0054 is not set
- Solving Python error: local variable ‘a’ referenced before assignment
- Solutions to error c2143: syntax error: missing ‘;’ before ‘type’ in C + + program compilation
- Java long type error: error: integer number too large
- PHP message:filesize(): stat failed for Error
- Error c2143: syntax error: missing ‘;’ before ‘type’
- Android Studio Series: after Android studio is opened, the project window will not be displayed.
- Python global variables and global keywords
- Solution of idea using @ Autowired annotation to report errors
- nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
- @Value sets the default value
- The C language qsort() function reports an error for overflow of – 2147483648 and 2147483648
- libxx.so: undefined reference, vector.reserve(n) [How to Solve]
- Common errors and modification methods of findbug