Strange consturct,

C

cyrusNew

Hi,

I have compiled with success something like this today :

CSize mySize;
CSize;
mySize;

and I dont really understand what it does, I think my compiler just throws
it away.

thanks,
 
V

Victor Bazarov

cyrusNew said:
I have compiled with success something like this today :

CSize mySize;
CSize;
mySize;

and I dont really understand what it does, I think my compiler just throws
it away.

If 'CSize' is a type (which I suspect it is), then the first statement
declares 'mySize' as an object of that type. The second statement should
not compile. If it's a declaration, a variable name is missing. If it
is a construction of a temporary, parentheses are missing. The third one
is fine. It's an expression that consists of one object, an lvalue named
'mySize'. That expression is evaluated and the result is thrown out.

So, all in all, the three statements are not part of a valid program due
to the second statement.

Victor
 
C

cyrusNew

If 'CSize' is a type (which I suspect it is), then the first statement
declares 'mySize' as an object of that type. The second statement should
not compile. If it's a declaration, a variable name is missing. If it
is a construction of a temporary, parentheses are missing. The third one
is fine. It's an expression that consists of one object, an lvalue named
'mySize'. That expression is evaluated and the result is thrown out.

So, all in all, the three statements are not part of a valid program due
to the second statement.

Victor

on MSVC second statement does compile, I checked with other classes and it
compiles, and even on fourth warning level there are no notifications. Gcc
does returns error.
 

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
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top