I don\'t understand why pointers aren\'t polymorphic types, since we can use base class pointers, which are pointing to derived classes, to call derived class\' virtual func
Your question suffers from incorrect usage of terminology. C++ language makes a very clear distinction between pointers themselves and objects these pointers point to. Pointer types are not polymorphic. There's nothing polymorphic about the pointer itself. What can really be polymorphic is the type the pointer points to. When a pointer points to a polymorphic type, we often [informally] call it polymorphic pointer (just as a shorthand for "a pointer that points to a polymorphic type"). But when it comes to things like typeid
, they see things very formally. For typeid
pointer types are never polymorphic.
And the compiler does not determine whether the pointer is polymorphic or not at run-time. This simple distinction is always immediately known at compile-time. Again, a pointer is referred to as polymorphic if it is declared as a pointer to polymorphic type. Polymorphic type is a class type that contains virtual functions (directly or indirectly). Obviously, the property of being polymorphic is a purely compile-time property of a type.
The only thing that is determined at run-time in such cases case is which specific type the pointed object has at the given moment.