| | |
c++ queries
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 19
Reputation:
Solved Threads: 0
This one is on References.
http://publib.boulder.ibm.com/infoce...ef/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.
http://publib.boulder.ibm.com/infoce...ef/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.
C++ Syntax (Toggle Plain Text)
// 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
Last edited by Tekmaven; Jul 31st, 2008 at 6:24 am. Reason: Code tags
Just because IBM says something is wrong doesn't mean VC++ agrees. Heck, VC++ could make
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.
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.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
•
•
Join Date: Jul 2008
Posts: 19
Reputation:
Solved Threads: 0
•
•
•
•
Just because IBM says something is wrong doesn't mean VC++ agrees. Heck, VC++ could makebillyboba 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.
It's a good day (or night) to quote the C++ Standard:
So I have a profound respect for IBM: they know generally known truth...
Well, another quote:
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:
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:
It's a list of a senseless references use cases: we have no chances to invent any correct semantics for enumerated linguistic UFOs...
•
•
•
•
8.3.2 References ...
4 There shall be no references to references, no arrays of references, and no pointers to references.
Well, another quote:
C++ Syntax (Toggle Plain Text)
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
Try to disprove yourself with another (successfully compiled) code snippets. Try to compile true reference to reference code:
cpp Syntax (Toggle Plain Text)
typedef int& Ref2int; Ref2int& still_born_ref2ref;
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
•
•
Join Date: Jul 2008
Posts: 19
Reputation:
Solved Threads: 0
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 !)
C++ Syntax (Toggle Plain Text)
typedef int& Ref; int a = 8; int &b = a; Ref& c = b; <span class="ad_notxt"><code class="inlinecode"> // reference to a reference is illegal ERROR</code></span>
![]() |
Similar Threads
- SQL Queries help (Database Design)
- Create Access Database using SQL queries (MS Access and FileMaker Pro)
- MS Access Queries not working in 2007 (MS Access and FileMaker Pro)
- snmp queries to printer (Networking Hardware Configuration)
- Multiple queries within one php file (PHP)
- Updating database with related tables and queries?? (VB.NET)
- Log files for submitted LDAP queries (Windows NT / 2000 / XP)
- Using exisiting queries within MS Access (ASP.NET)
- securit issues fundamental - few queries - follow up (Viruses, Spyware and other Nasties)
- request for ansi sql queries equalent to MS access (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: the problem of gettimeofday
- Next Thread: iterate a 3d vector
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






