Connecting Tech Pros Worldwide Forums | Help | Site Map

Strange consturct,

cyrusNew
Guest
 
Posts: n/a
#1: Jul 23 '05
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,




Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Strange consturct,


"cyrusNew" <deselect@wp.pl> wrote...[color=blue]
> 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.[/color]

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


cyrusNew
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Strange consturct,


>>[color=blue][color=green]
>> CSize mySize;
>> CSize;
>> mySize;
>>
>> and I dont really understand what it does, I think my compiler just
>> throws it away.[/color]
>
> 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[/color]

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.


Closed Thread