Connecting Tech Pros Worldwide Help | Site Map

Strange consturct,

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 11:32 PM
cyrusNew
Guest
 
Posts: n/a
Default Strange consturct,

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 22nd, 2005, 11:32 PM
Victor Bazarov
Guest
 
Posts: n/a
Default 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 22nd, 2005, 11:32 PM
cyrusNew
Guest
 
Posts: n/a
Default 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.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.