Answer the question
In order to leave comments, you need to log in
What does a reference without a type mean?
long x = 10;
const &y = x;
cout << typeid(y).name() << '\n'; // тип int, а не long
x += 10;
cout << y; // 10, а не 20
Answer the question
In order to leave comments, you need to log in
const &y = x;
It's not a link without a type, but syntactically invalid code that won't get translated outside of GCC.
Because If you're using GCC, you should be aware that it doesn't follow the standard in some cases.
Particularly in this case.
C++ does not have a default type, unlike C, where the default type is int
. If in C the code const y = x
is syntactically correct and implies const int y = x
, then in C++ the same code is already syntactically incorrect and will not be translated .
GCC in your code is moving away from the C++ standard in favor of C-like behavior.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question