lundi 15 février 2021

why (var) is considered as lvalue?

I was trying to understand decltype in C++ through one of the stack overflow questions What is decltype and how is it used?

Part of accepted answer is as below.

int foo();
int n = 10;

decltype(n) a = 20;             // a is an "int" [id-expression]

decltype((n)) b = a;            // b is an "int &" [(n) is an lvalue]

decltype(foo()) c = foo();      // c is an "int" [rvalue]

decltype(foo()) && r1 = foo();  // int &&
decltype((n)) && r2 = n;        // int & [& && collapses to &]

I couldn't understand below statement.

decltype((n)) b = a; // b is an "int &" [(n) is an lvalue]

can any one please let me know why (n) is considered as lvalue.

Aucun commentaire:

Enregistrer un commentaire