Reference to a reference in c++ -


i going through reference concepts in c++ , little confused statement in c++ complete reference.

you cannot reference reference

so happening in case:

    int  var = 10;     int& ref = var;     int& r_ref = ref;     r_ref++;     cout << "var:" << var << "ref:" << ref << "r_ref:" << r_ref << endl; 

the output getting is:

var:11  ref:11  r_ref:11 

it's confusingly worded. mean can't have int& & type (note there such thing int&&, that's different type of reference).

in code, reference ref referring object denoted var. names ref , var can used interchangeably refer same object. when int& r_ref = ref;, you're not making reference reference, you're making reference same object once again.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -