Monday, November 11, 2013

Reference is not an object.

Newsgroup: comp.lang.c++

Subject: Reference is not an object.

From: wy <warmyouth@...>

Date: Mon, 11 Nov 2013 09:08:32 +0800



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?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?126005-Reference-is-not-an-object&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment