W
wy
I'm reading "C++ Primer", and it emphasizes "reference is not an object".
In P51, it says "Because references are not objects, we may not define a
reference to a reference." And in P52, it says "Because references are
not objects, they don't have addresses. Hence, we may not define a
pointer to a reference."
But the following code works with g++.
#include <iostream>
using namespace std;
int main()
{
int val = 0xfe;
int &ref= val;
int &r = ref;
int *p = &ref;
cout << "val = " << val << endl;
cout << "ref = " << ref << endl;
cout << "r = " << r << endl;
cout << "*p = " << *p << endl;
return 0;
}
Is the feature not standard, or do I misunderstand?
In P51, it says "Because references are not objects, we may not define a
reference to a reference." And in P52, it says "Because references are
not objects, they don't have addresses. Hence, we may not define a
pointer to a reference."
But the following code works with g++.
#include <iostream>
using namespace std;
int main()
{
int val = 0xfe;
int &ref= val;
int &r = ref;
int *p = &ref;
cout << "val = " << val << endl;
cout << "ref = " << ref << endl;
cout << "r = " << r << endl;
cout << "*p = " << *p << endl;
return 0;
}
Is the feature not standard, or do I misunderstand?