Difference between variable declarations...

S

Sharad Kala

Rolf Magnus said:
The former is a reference to an integer, the latter is an integer.

Also former is not legal C++, a reference has to be initialized for sure.

Sharad
 
S

Sharad Kala

Victor Bazarov said:
sure.

It us legal if it appears inside a class definition.

Yes.
To OP: Even then you need to bind the reference in the initializer list.

Sharad
 
S

Sharad Kala

Rolf Magnus 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.

Sharad
 
R

Rolf Magnus

Sharad said:
Not totally wrong.
int main()
{
int& i; // Not legal
}

Well, can you name one language construct that can be used _everywhere_ in a
program?
Given the context in which OP asked the question, it seemed that it was
not in a class definition.

Actually, I don't see any context.
The point I was trying to stress was that you cannot leave the reference
uninitialized.

And I agreed to that.
 
A

Alf P. Steinbach

* Rolf Magnus:
Actually, I don't see any context.

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...
 
P

pmatos

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...

Indeed, I didn't want to know about context specific questions but I
didn't know it had to be initialized until before reading section 5.5
of C++PL. Anyway, I already understood what it is for. :)

Thanks a lot people and don't get mad about context specific
questions... :)

Cheers,

Paulo Matos
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top