Displaying an Employee’s Type

Lines 55–62 display each employee’s object type and uses the delete operator to deallocate the dynamic memory to which each vector element points. Operator typeid (line 59) returns a reference to an object of class type_info that contains the information about the type of its operand, including the name of that type. When invoked, type_info member function name (line 59) returns a pointer-based string containing the typeid argument’s type name (e.g., "class BasePlusCommissionEmployee"). To use typeid, the program must include header <typeinfo> (line 8).

Image Portability Tip 12.1

The string returned by type_info member ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.