The reinterpret_cast operator converts one type into a fundamentally different type. : cast « Class « C++






The reinterpret_cast operator converts one type into a fundamentally different type.

   
#include <iostream>
using namespace std;
   
int main()
{
  int i;
  char *p = "This is a string";
   
  i = reinterpret_cast<int> (p); // cast pointer to integer
   
  cout << i;
   
  return 0;
}
  
    
    
  








Related examples in the same category

1.Don't need a cast to go up the inheritance hierarchy
2.class type-casting
3.The const_cast operator is used to explicitly override const and/or volatile in a cast.
4.Use const_cast on a const reference.Use const_cast on a const reference.
5.The static_cast operator performs a nonpolymorphic cast.
6.The dynamic_cast performs a run-time cast that verifies the validity of a cast.
7.Replacing typeid with dynamic_cast