This one is on References.

http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr110.htm

in the above link (from IBM), they clearly mention that a reference to a (pointer to a reference ) is not allowed.They also say that a reference to other references is not allowed. However, when i tried out both these cases in code, it worked on VC++.

Can you please help me with this ?

I have the snippet for you right below.

// reference to other references
int a = 10;

int& b = a;//b is a ref to a

int& c = b;// c is a ref to b which is a ref

cout << c;// i get the output as 10 

////////////////////////////////////////////////////////////////////////////////////////

// reference to ( Pointer to a Reference )



int a = 10;

int& b = a;//b is a ref to a

int* p=&b;// pointer to a reference

cout << *p <<endl; // output is 10

int** ptr=&p;// Pointer to a (Pointer to a Reference)

cout << **ptr;//output is 10

Just because IBM says something is wrong doesn't mean VC++ agrees. Heck, VC++ could make billybob a primitive data type and still call itself a C++ compiler (though few others would agree - and that's really what matters). Whatever is in the ISO standard for C++ is what is allowed. Implementations of C++ can bend the rules if they wish, no one can stop them.

As to whether the ISO standard says references to pointers to references are allowed, I don't know.

Also, use [code] code here [/code] tags.

Just because IBM says something is wrong doesn't mean VC++ agrees. Heck, VC++ could make billybob a primitive data type and still call itself a C++ compiler (though few others would agree - and that's really what matters). Whatever is in the ISO standard for C++ is what is allowed. Implementations of C++ can bend the rules if they wish, no one can stop them.

As to whether the ISO standard says references to pointers to references are allowed, I don't know.

Also, use [code] code here [/code] tags.

Thanks ! I got the perspective . What i did want to know was whether this was allowed as part of the ISO Standards for C++ .

It's a good day (or night) to quote the C++ Standard:

8.3.2 References ...
4 There shall be no references to references, no arrays of references, and no pointers to references.

So I have a profound respect for IBM: they know generally known truth...

Well, another quote:

int a = 10;
int& b = a;//b is a ref to a
int& c = b;// c is a ref to b which is a ref /// OOPS! See below
cout << c;// i get the output as 10

The c is not a reference to reference to int. It's a reference to int. The reference initializator (b) is dereferenced in this syntax position and yields a. That's all right.

Try to disprove yourself with another (successfully compiled) code snippets. Try to compile true reference to reference code:

typedef int& Ref2int;
Ref2int& still_born_ref2ref;

and see VC++ reaction on this C++ Standard break-through...

A reference is simply a(nother) NAME of an object. Can you imagine a reference to so abstract entity called a NAME? Can you explane what's such a beast as a pointer (==address of) to a NAME? Think about references concept in C++. A reference is an absolutely imperceptible thing: it immediately dereferencing in every context (transmutes to the referenced object). It transmutes to its target object in sizeof operator argument (where arrays do not transmute to a pointers to base class as they usually do in all others contexts).

Back to IBM:

You cannot have references to any of the following:
Other references
Bit fields
Arrays of references
Pointers to references

It's a list of a senseless references use cases: we have no chances to invent any correct semantics for enumerated linguistic UFOs...

thanks for the information ArkM. That was of great help. I tried out the following program and this is what i ended up with ( as expected !)

typedef int& Ref;
    int a = 8;
    int &b = a;
    Ref& c = b;`// reference to a reference is illegal ERROR` 

Edited 3 Years Ago by happygeek: fixed formatting

Query 2. When we instantiate an object in C++, a constructor gets called.
How is this implemented internally ?
What is the C++ run time library ? Does it come into the picture ?
I would also want to know, who is it that calls the Main function in a program?

This article has been dead for over six months. Start a new discussion instead.