Retrieving a c++ class name programmatically

前端 未结 5 1820
Happy的楠姐
Happy的楠姐 2020-12-04 13:23

I was wondering if it is possible in C++ to retrieve the name of a class in string form without having to hardcode it into a variable or a getter. I\'m aware that none of th

5条回答
  •  执笔经年
    2020-12-04 13:41

    The typeid(obj).name() thing always gives the type of the variable as it was declared, not the actual type (class) of the object. If the variable obj is assigned to an instance of a subclass of the class that obj was declared as, typeid doesn't reveal that, unfortunately.

提交回复
热议问题