Home C++ Introduction Decisions Loops Input/Output Functions Stack and Heap References Arrays Searching and Sorting Recursion Pointers Character and Strings Structures Classes Inheritance Casting Exceptions Templatess STL Modern C++ Misc Books ----

Casting


Contents

Exercises



File: ex1.cpp
#include <iostream>
#include <vector>
using namespace std;

class A
{
};

class B : public A
{
};

class C : public A
{
};


int main()
{
    int x1 ;
    float x2 = 10.5 ;

    x1 = (int) x2 ;
    //TO DO convert using new style
    //STATIC_CAST


    A* ptrA = new B() ;
    C* ptrC ;
    ptrC = (C*)ptrA ;
    //TO DO convert using new style
    //DYNAMIC_CAST

    int i1 = 10 ;
    const int* ptr = &i1 ;
    int* ptr1 = (int*) ptr ;
    //TO DO convert using new style
    //CONST_CAST


    char* ptr2 ;
    int* ptr3 = &i1 ;
    ptr2 = (char*) ptr3  ;
    //TO DO convert using new style
    //REINTERPRET CAST





   return 0;
}





























File: ex1s.cpp