Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
C++ ではtypeid、演算子を使用してポリモーフィック クラスの名前を取得できます。
typeid
const char* name = typeid( CMyClass ).name();
const char*返されたポインタが指す文字列は、プログラムでどのくらいの期間使用できますか?
const char*
rtti を持つクラスが存在する限り。したがって、単一の実行可能ファイルを扱う場合は、永遠に. ただし、Dynamic Link Librariy 内のクラスの場合は少し異なります。場合によっては、アンロードできます。
によって返されるメモリはtype_info::name()、アプリケーションの存続期間中使用できます。
type_info::name()