More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Tuesday, 25 August 2009 12:56:35 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 523

Compare C++ cast operators
Old-style casting, unsafe
- (typename)expression
- typename(expression)

New cast operators, varies
- dynamic_cast<type>(expression)
- const_cast<type>(expression)
- static_cast<type>(expression)
- reinterpret_cast<type>(expression)


dynamic_cast
Code:
dynamic_cast<T>(expression)

- Used only on pointer or reference types
- Can be used for up-cast or down-cast (see also Run Time Type Information RTTI)
- Only for polymorphic types with virtual-functions as these objects have the information about the type: the virtual function table
- Returns null if the cast is unsuccessful

const_cast
Code:
const_cast<T>(expression)

- Is used to remove or add const-ness
- Usually, you should design your variables or methods such that you won’t have to use const_cast
- Failure causes compiler errors

static_cast
- Works where implicit conversion exists
- standard or user-defined conversion
- up-casts
- Safer than (typename)expression or typename(expression)
- e.g. won’t cast int* to float*
- Failure causes a compiler error
- No dynamic checking is done!

reinterpret_cast
- Circumvents the type checking of C++; Very dangerous
- Very implementation-dependent
- Rarely used

Edited by user Tuesday, 25 May 2010 2:51:22 AM(UTC)  | Reason: Not specified

Sponsor
jimmy007  
#2 Posted : Monday, 24 May 2010 7:08:49 PM(UTC)
jimmy007

Rank: Advanced Member

Reputation:

Groups: Member
Joined: 3/03/2010(UTC)
Posts: 3

Thanks for topic

Regards
Shubhinetwork
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.