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?
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:
http://www.research.att.com/~bs/Bjarne.jpg
Re: Reference and address of operator
Is this Stroustroup himself?
Nice picture :D
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.
Re: Reference and address of operator
I have put that as my new wallpaper.
I love you Bjarne :-*!
Re: Reference and address of operator
I never know there are some people actually worshipping him. :D :D :D
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.
Re: Reference and address of operator
Quote:
Originally Posted by Kheun
I never know there are some people actually worshipping him. :D :D :D
He is not worshipping him.. You will find many worshippers though...
He actually is in LOVE with him ... el o vee ee... love.. :D
Re: Reference and address of operator
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).
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?
Re: Reference and address of operator
This should be in a new thread...
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.