C++ provides a typeid operator that can be used to query the concrete type of a pointer
Question:
C++ provides a typeid operator that can be used to query the concrete type of a pointer or reference variable:
if (typeid(*p) == typeid(my_derived_type)) ...
Values returned by typeid can be compared for equality but not assigned. They also support a name() method that returns an (implementation dependent) character string name for the type. Give an example of a program fragment in which these mechanisms might reasonably be used.
Unlike more extensive reflection mechanisms, typeid can be applied only to (instances of) classes with at least one virtual method. Give a plausible explanation for this restriction.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Question Posted: