Wednesday, 15 June 2011

c++ - Reference variable equals another reference variable? -



c++ - Reference variable equals another reference variable? -

this question has reply here:

can reassign reference in c++? 4 answers

consider following:

int somea = 1; int someb = 2; int &a = somea; int &b = someb; = b; // happens here?

what's happening here references? curious.

having 2 reference variables equal each other in not error. may confusing. however, code not setting reference reference, it's altering value of _a 1 2, what's in _b.

you can set reference 1 time [where initialized]. 1 time it's been initialized, become alias original variable.

you this:

int &a = _a; int &b = _a;

and

a = b;

would store value 1 _a, has value 1.

c++

No comments:

Post a Comment