Use the typeid operator instead of the virtual function you wrote that returns the name of a shape as a char* value.
The operator typeid() can be applied to a type name or to an expression to determine the exact type of the argument.
The operator returns a reference to the class type_info, which is supplied by the system and is defined in the header file type_info.h.
Some possible arguments of typeid() are
- a reference to a class
- a pointer, dereferenced with *
Borland C++ 4.0 uses typeinfo.h instead of type_info.h.
If you use MSVC, select the Run-Time Type Information (RTTI) option in order to enable the typeinfo.h utilities.
The class type_info provides a name() member function returning a string that is the type name. It also provides overloadedequality operators.
Remember to check the local implementation for the complete interface of this class.