Reputation: 23511
If i define three objects like the following:
const string & textA = messages.at(0),
textB = messages.at(1),
textC = messages.at(2);
Are textB
and textC
actually a reference?
Do I have to place the &
in front of both textB
and textC
?
Thanks!
Upvotes: 2
Views: 415
Reputation: 2886
use this notation instead and you will see what happens:
const string &textA = .., // reference
&textB = .., // reference
textC = ..; // value
Same thing applies to pointers:
const string *textA = .., // pointer
*textB = .., // pointer
textC = .. ;// value
Combined
const string *textA = .., // pointer
&textB = .., // reference
textC = .. ;// value
Upvotes: 2
Reputation: 1137
textB
and textC
are not references. Think of the &
as if it belongs with the variable, not the type.
(Just checked with g++)
Upvotes: 5