0

Hey guys how do you guys output an object's type. For instance lets say i had the following line of code

Pokemon pikachu;

and I want to output the object(aka pikachu)'s type (which in this case is Pokemon). Is there a way to do so?

Brogrammer93
  • 97
  • 1
  • 2
  • 9
  • No, not generally. Types are part of the static language, and they don't generally exist at runtime of the compiled program. You can associate an implementation-defined string with some types via `typeid(x).name()`, but that's of limited use. – Kerrek SB May 31 '15 at 02:21
  • Possible Duplicate: http://stackoverflow.com/q/3649278/1702990 – Sinkingpoint May 31 '15 at 02:21
  • There's no "one right way", so you can write code to do this however you want. You can, for example, provide a `getType` function in all your classes or you can derive them from a common base class that has this as a virtual function. – David Schwartz May 31 '15 at 02:27

0 Answers0