P
pmatos
Hi all,
What's the difference between:
int& i;
and
int i;
?
Cheers,
Paulo Matos
What's the difference between:
int& i;
and
int i;
?
Cheers,
Paulo Matos
pmatos said:Hi all,
What's the difference between:
int& i;
and
int i;
?
Rolf Magnus said:The former is a reference to an integer, the latter is an integer.
Sharad said:Also former is not legal C++, a reference has to be initialized for sure.
Victor Bazarov said:sure.
It us legal if it appears inside a class definition.
Sharad said:Also former is not legal C++,
a reference has to be initialized for sure.
Rolf Magnus said:Wrong.
Sharad said:Not totally wrong.
int main()
{
int& i; // Not legal
}
Given the context in which OP asked the question, it seemed that it was
not in a class definition.
The point I was trying to stress was that you cannot leave the reference
uninitialized.
Actually, I don't see any context.
Alf said:* Rolf Magnus:
Note the semicolon at the end in the Original Posting:
int& i;
This is only valid in a class definition.
But since the question was what does it mean, it probably doesn't
imply very much about context...
pmatos said:Thanks a lot people and don't get mad about context specific
questions...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.