Using static_cast: base and derived class : static_cast « Development « C++ Tutorial






#include <iostream>
#include <ostream>

class base {};
class derived : public base {};
class other : public base {};

int main()
{
  base* b = new derived;
  static_cast<derived&>(*b); 
  static_cast<other*>(b);    

  derived* d = new derived;
  b = d;
  b = static_cast<base*>(d); 

}








5.20.static_cast
5.20.1.Use static_cast.
5.20.2.Using static_cast: base and derived class
5.20.3.Using static_cast: for enum data type