C++ still supports C-style cast, as in
int i = (int) 7.333;
Nonetheless, C-style cast notation is problematic for several reasons. First, 
the operator () is already used
excessively in the language: in a function call, in precedence reordering of 
expressions, in operator overloading, and
in other syntactic constructs. Second, C-style cast carries out different 
operations in different contexts -- so different
that you can hardly tell which is which. It can perform an innocuous standard 
cast, such as converting an enum value
to an int; but it can also cast two nonrelated types to one another. In 
addition, a C-style cast can be used to remove
the const or volatile qualifiers of an object (and in earlier stages of C++, 
the language was capable of
performing dynamic casts as well).

for more examples and info search in msdn for static_cast and reinterpret_cast 
and dynamic_cast

i hope it was helpfull.


----- Original Message ----
From: Thomas Hruska <[EMAIL PROTECTED]>
To: [email protected]
Sent: Wednesday, July 4, 2007 6:51:07 PM
Subject: Re: [c-prog] C++ Casting

Victor A. Wagner Jr. wrote:
> Keanu Reaves wrote:
>> hi shweta i'm frm india...The Question You Asked Has No Difference
> you mean the results of the program will be the same.
>> you can use one of them..but the thing is that it may give you unconditional 
>> results.if u r on orkut then gimme id.ok.!
>>
>> Thomas Hruska <[EMAIL PROTECTED] .com> wrote: Mickey Mathieson wrote:
>> 
>>> --- shvetakapoor2002_ cplusplus
>>> <shvetakapoor2002_ cplusplus@ yahoo.com> wrote:
>>>
>>> 
>>>> Hi All,
>>>>
>>>> Please help me in understanding what's the
>>>> difference between the two 
>>>> statements below
>>>>
>>>> [1] cout << "Number: " << static_cast< int>(3.14159)
>>>> << "\n";
>>>>
>>>> [2] cout << "Number: " << (int)3.14159 << "\n";
>>>>
>>>> Basically I want to know the difference in using
>>>> static_cast< int> and 
>>>> using (int)
>>>>
>>>> Thanks,
>>>> Shveta
>>>>
>>>>
>>>> 
>>> http://www.cprogram ming.com/ reference/ typecasting/ staticcast. html
>>>
>>>
>>> Mickey M.
>>> Construction Partner Inc.
>>> http://www.construc tionpartner. com
>>> 
>> Um...
>>
>> double result = static_cast< double>(4) /5;
>>
>> Pretty sure that won't work
> of course it will

Okay. Conceded. Personally, I prefer making sure the compiler knows 
exactly what I mean and I never rely on implicit rules. It is a habit 
I've learned over the years after getting bitten by numerous bugs. So I 
will always prefer:

double result = ((double)4) / ((double)5);

OR

double result = 4.0 / 5.0;

>> Frankly, I've not seen much of a difference between the two types of 
>> casts and personally prefer the old C-style casts because it requires 
>> pressing fewer keys.
> bad idea. Read Meyers on the topic

I've read enough on static_cast to know it doesn't do much of anything 
different from C-style casting for fundamental data types (int, double, 
char, float, short, long, unsigned, signed). I use static_cast for 
classes and other more complex types though because there ARE 
compile-time benefits there.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.0
Get on task. Stay on task.

http://www.CubicleS oft.com/MyTaskFo cus/





      
____________________________________________________________________________________
Shape Yahoo! in your own image.  Join our Network Research Panel today!   
http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 



[Non-text portions of this message have been removed]

Reply via email to