class type-casting : cast « Class « C++






class type-casting

  
#include <iostream>
using namespace std;

class CDummy {
    float i,j;
};

class CAddition {
  int x,y;
  public:
  CAddition (int a, int b) { x=a; y=b; }
  int result() { return x+y;}
};

int main () {
  CDummy d;
  CAddition * padd;
  padd = (CAddition*) &d;
  cout << padd->result();
  return 0;
}
  
    
  








Related examples in the same category

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