   static_cast C++
  whats static_cast?? and when I should use it??its better then the normal cast?? should I use it??thanks    PROgrammer  
  Use static_cast to typecast related types (between integer types, for example). Use dynamic_cast to cast (pointers) up and down an inheritance tree. Use reinterpret_cast to cast unrelated (and potentially unsafe) types. That isn''t canonical, but it''s a fairly good rule of thumb.    [ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions ]Thanks to Kylotan for the idea!  ;  dynamic_cast shouldn''t be used for up-casting of pointers only down-casting.  A pointer to a derived class may always be safely up-casted to a base class using a static_cast, with no overhead.  dynamic_cast will check to make sure that the down-cast is valid.;quote:Original post by Anonymous Poster  A pointer to a derived class may always be safely up-casted to a base class using a static_cast, with no overhead.  Don''t be silly. There''s no need to explicitly cast to achieve that.  ;  Sorry, I''m very very new but I seriously cannot find any help anywhere else. I need to work to a C program that requires me to use dynamic casting: (as such)// not written by me ... function(void* data, ...){int* parameter = *(int**)data; // statement......function2(parameter);....}I am suppose to pass the address of data into fuction2 which accepts an int[]. I know that the solution is to use the typecast (int*) itself. But this statement makes logical sense. Isn''t *(int**) or int* the same?But I do not know why this statement leads to wrong results eventually.Can anyone explain to me .. newbie here. And does anyone know any website i can learn about the compiler and how typecasting is done?? Dun scold me learn C not longer than 1 year...   Please help this poor kid... ;  It would have been better to create a new thread rather than necro a thread from 2 years ago.   Colin Jeanne | Invader''s Realm