Created
April 12, 2019 10:33
-
-
Save FONQRI/74b778490330234f795a5b2f6f133ea8 to your computer and use it in GitHub Desktop.
Define name string with macro and iit it with class name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/type_index.hpp> | |
#include <iostream> | |
#define DEFINE_NAME \ | |
std::string name \ | |
{ \ | |
boost::typeindex::type_id<decltype(*this)>().pretty_name() \ | |
}; | |
class Test2 | |
{ | |
public: | |
DEFINE_NAME | |
}; | |
int main() | |
{ | |
Test2 t; | |
std::clog << t.name << std::endl; // human readable | |
return 0; | |
} | |
//output : | |
// Test2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment