reference question
-
I found, a statement, int &a = 1; the statement can be built in QT Creator, mingw_64. while on Programiz: Learn to Code for Free[^] Got,
gcc /tmp/BlXEG8NqhU.c -lm
/tmp/BlXEG8NqhU.c: In function 'main':
/tmp/BlXEG8NqhU.c:6:15: error: expected identifier or '(' before '&' token
6 | const int &a = 2;so the int &a = 1; is that right? a is a bias name of "1" in rodata?
-
I found, a statement, int &a = 1; the statement can be built in QT Creator, mingw_64. while on Programiz: Learn to Code for Free[^] Got,
gcc /tmp/BlXEG8NqhU.c -lm
/tmp/BlXEG8NqhU.c: In function 'main':
/tmp/BlXEG8NqhU.c:6:15: error: expected identifier or '(' before '&' token
6 | const int &a = 2;so the int &a = 1; is that right? a is a bias name of "1" in rodata?
I suspect that whatever QT Creator is doing is somehow creating a
const reference
. e.g.int &a = 1; // fails to compile
const int &b = 2; // compiles fineConsider what
int &a = 1
means: I.E. create a reference to the integer 1. If that were to compile successfully then considerint &a = 1;
a = 2;
std::cout << 1 + 1 << '\n';By the rules of C++, at least as I understand them, that should print 4, since you've changed the value of
1
to2
at the assignment statement.Keep Calm and Carry On
-
I found, a statement, int &a = 1; the statement can be built in QT Creator, mingw_64. while on Programiz: Learn to Code for Free[^] Got,
gcc /tmp/BlXEG8NqhU.c -lm
/tmp/BlXEG8NqhU.c: In function 'main':
/tmp/BlXEG8NqhU.c:6:15: error: expected identifier or '(' before '&' token
6 | const int &a = 2;so the int &a = 1; is that right? a is a bias name of "1" in rodata?