Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 07, 2016 Get class name of C++ class at runtime | ||||
---|---|---|---|---|
| ||||
Is it possible to get the name of a C++ class, "extern(C++) class Foo {}", at runtime just as it's possible to do the same for a D class, like "object.classinfo.name"?
--
/Jacob Carlborg
|
July 07, 2016 Re: Get class name of C++ class at runtime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Thursday, 7 July 2016 at 09:59:23 UTC, Jacob Carlborg wrote:
> Is it possible to get the name of a C++ class, "extern(C++) class Foo {}", at runtime just as it's possible to do the same for a D class, like "object.classinfo.name"?
Maybe with a template?
----
void class_name(T)(T obj) if (is(T == class)) {
writeln(T.stringof);
}
----
|
July 07, 2016 Re: Get class name of C++ class at runtime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | 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. -- /Jacob Carlborg |
July 07, 2016 Re: Get class name of C++ class at runtime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | 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 |
July 07, 2016 Re: Get class name of C++ class at runtime | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 07/07/16 15:19, Steven Schveighoffer wrote: > 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 Yeah, that works, thanks. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation