c++ - C++11 type of variable in expression? -


in c++11 i'm confused difference between types t , reference t apply expressions name variables. consider:

int main() {     int x = 42;     int& y = x;      x; // (1)     y; // (2) } 

what type of expression x in (1) in above? int or lvalue reference int ? (its value category lvalue, separate type)

likewise type of expression y @ (2) in above? int or lvalue reference int ?

it says in 5.1.1.8:

the type of [an identifier primary expression] type of identifier. result entity denoted identifier. result lvalue if entity function, variable, or data member , prvalue otherwise.

the bit you're missing (§5/5):

if expression has type “reference t” (8.3.2, 8.5.3), type adjusted t prior further analysis.

so although identifier y has type int&, expression y has type int. expression never has reference type, type of both of expressions int.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -