Inheritance/Polymorphism  «Prev 

C++ typeid operator - Exercise

Using typeid

Objective: Use the typeid operator instead of the virtual function you wrote that returns the name of a shape as a char* value.

Instructions

Write a main() function that uses the typeid operator to return the name of a shape as a char* value. Print out the name of each shape subtype defined for the shape class. Your system will need to have type_info.h to complete this exercise.
Here is the shape class hierarchy for reference:

class shape {
public:
   virtual double  area() const { return 0; }
   //virtual double area is default behavior
protected:
   double  x, y;
};

class rectangle : public shape {
public:
   double  area() const { return (height * width); }
private:
   double  height, width;
};

class circle : public shape {
public:
   double  area() const
     { return (PI * radius * radius);}
private:
   double   radius;
};
This code is also available in a file named shape.cpp, which can be found in the compressed course download file available on the Resources page.
Paste your code below and click the Submit button when you are ready to submit this exercise.