N
nvangogh
According to c++ primer "once initialized, a reference remains bound to
it's initial object. There is no way to rebind a reference to refer to a
different object." moreover, "Because references are not objects, we may
not define a reference to a reference".
I am confused because this code seems to at least define a reference to
a reference:
#include <iostream>
int main()
{
int i = 0, &r1 = i;
double d = 5.0, &r2 = d;
r2 = r1;
std::cout << r2 << std::endl;
return 0;
}
When run this outputs r2 as 0. Why is this?
it's initial object. There is no way to rebind a reference to refer to a
different object." moreover, "Because references are not objects, we may
not define a reference to a reference".
I am confused because this code seems to at least define a reference to
a reference:
#include <iostream>
int main()
{
int i = 0, &r1 = i;
double d = 5.0, &r2 = d;
r2 = r1;
std::cout << r2 << std::endl;
return 0;
}
When run this outputs r2 as 0. Why is this?