How can I get the class name from a C++ object?

前端 未结 8 2142
名媛妹妹
名媛妹妹 2020-11-29 20:56

Is it possible to get the object name too?

#include

class one {
public:
    int no_of_students;
    one() { no_of_students = 0; }
    void new         


        
8条回答
  •  攒了一身酷
    2020-11-29 21:31

    To get class name without mangling stuff you can use func macro in constructor:

    class MyClass {
        const char* name;
        MyClass() {
            name = __func__;
        }
    }
    

提交回复
热议问题