|
-
March 2nd, 2006, 09:12 AM
#1
Reference and address of operator
Why did C++ creators used the same symbol for references and address of operator. When I was a begineer I found it very difficult to differentiate between the two though the right type could be obtained from the context. Is there any advantage in doing so?
If there is no love sun won't shine
-
March 2nd, 2006, 09:33 AM
#2
Re: Reference and address of operator
[ Redirected thread ]
Although later you'll consider that it's not so hard to differentiate from context, this guy is the only one who can give you the best answer:
-
March 2nd, 2006, 09:37 AM
#3
Re: Reference and address of operator
Is this Stroustroup himself?
Nice picture
If there is no love sun won't shine
-
March 2nd, 2006, 09:42 AM
#4
Re: Reference and address of operator
Yea, it's taken from Bjarne Stroustrup's homepage.
You can take a look in it and maybe you can find the answer.
-
March 2nd, 2006, 09:49 AM
#5
Re: Reference and address of operator
I have put that as my new wallpaper.
I love you Bjarne :-*!
"I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
FORZA MILAN!!!
-
March 2nd, 2006, 08:05 PM
#6
-
March 2nd, 2006, 08:16 PM
#7
Re: Reference and address of operator
It may be confusing, but I don't remember having trouble distinguishing between the two different uses. It's true that something like "void f(int &i)" looks weird when you come from C without references, but then again, the contextual differences are pretty clear though.
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
March 3rd, 2006, 01:31 AM
#8
Re: Reference and address of operator
 Originally Posted by Kheun
He is not worshipping him.. You will find many worshippers though...
He actually is in LOVE with him ... el o vee ee... love..
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
March 3rd, 2006, 02:57 AM
#9
Re: Reference and address of operator
I love this man too...
"I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
FORZA MILAN!!!
-
March 3rd, 2006, 06:35 AM
#10
Re: Reference and address of operator
When I first saw that syntax, I thought it was intuitive, but of course I understand that overuse of the same keywords in different contexts, with different meaning, may be confusing.
For example the "static" keyword has at least three meanings (and a new one in C99).
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
March 3rd, 2006, 08:06 AM
#11
Re: Reference and address of operator
I know two meanings of the static keyword.
1. Life time that of the program.
2. Creation of one instance.
Is Internal Linkage the third one?
Last edited by miteshpandey; March 3rd, 2006 at 08:36 AM.
If there is no love sun won't shine
-
March 3rd, 2006, 08:13 AM
#12
Re: Reference and address of operator
This should be in a new thread...
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
March 3rd, 2006, 11:45 AM
#13
Re: Reference and address of operator
static means "instance-independent" when used with members of a class.
It means "internal storage" when used with data/functions at namespace-scope level... what is funny, because with class data members it has external linkage.
It means "static storage duration" for function's static variables.
Since internal storage data implies static storage duration, you can deem that these two last form of "static" have the same semantics (i.e. "internal storage).
But for a beginner, it is not very intuitive that:
Code:
static int hello()
{
static int k=42;
return ++k;
}
In that code, the two static words have the same "meaning".
However if the auto keyword was not implicit when declaring variables inside a function, that may seem more intuitive to beginners.
That is why I said that there were three meanings.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|