Get class name of C++ class at runtime

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 7 06:19:56 PDT 2016


On 7/7/16 9:02 AM, Jacob Carlborg wrote:
> On 07/07/16 12:31, Namespace wrote:
>
>> Maybe with a template?
>>
>> ----
>> void class_name(T)(T obj) if (is(T == class)) {
>>      writeln(T.stringof);
>> }
>> ----
>
> I want the string of the runtime type, the most derived type.
>

Is this what you are looking for? I don't think you can do this in 
D-land, but you can probably hook it from C++:

http://en.cppreference.com/w/cpp/language/typeid

-Steve


More information about the Digitalmars-d-learn mailing list