Connecting Tech Pros Worldwide Help | Site Map

Strange consturct,

  #1  
Old July 23rd, 2005, 12:32 AM
cyrusNew
Guest
 
Posts: n/a
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,



  #2  
Old July 23rd, 2005, 12:32 AM
Victor Bazarov
Guest
 
Posts: n/a

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


  #3  
Old July 23rd, 2005, 12:32 AM
cyrusNew
Guest
 
Posts: n/a

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