www.digitalmars.com         C & C++   DMDScript  

D - rtti?

reply "Dario" <supdar yahoo.com> writes:
(This surely has been already told. I remember I have read about it
somewhere, but I don't remember where... I apologize.)

What's the D sintax for RTTI? I tried
if(instance.typeinfo === Class.typeinfo) {/*...*/}
but this doesn't work. I tried
if(instance.classinfo === Class.classinfo) {/*...*/}
but this generates an internal error.

How should I write the D equivalent of the following C++ code?

#include <typeinfo>
class Class {} instance;
if(typeid(instance) == typeid(Class)) {/*...*/}

Thanks in advance for helping me! Dario
Jul 03 2002
parent reply Burton Radons <loth users.sourceforge.net> writes:
Dario wrote:
 (This surely has been already told. I remember I have read about it
 somewhere, but I don't remember where... I apologize.)
We discussed it a few weeks ago, but your problem is new.
 What's the D sintax for RTTI? I tried
 if(instance.typeinfo === Class.typeinfo) {/*...*/}
 but this doesn't work. I tried

 if(instance.classinfo === Class.classinfo) {/*...*/}
 but this generates an internal error.
This is correct and should work. Could you boil it down to the smallest amount of code that can cause the internal error and then post that?
Jul 04 2002
parent reply "Dario" <supdar yahoo.com> writes:
 (This surely has been already told. I remember I have read about it
 somewhere, but I don't remember where... I apologize.)
 We discussed it a few weeks ago, but your problem is new.
 What's the D sintax for RTTI? I tried
 if(instance.typeinfo === Class.typeinfo) {/*...*/}
 but this doesn't work. I tried
 if(instance.classinfo === Class.classinfo) {/*...*/}
 but this generates an internal error.
 This is correct and should work.  Could you boil it down to the smallest
 amount of code that can cause the internal error and then post that?
This compiles good but emits a runtime error: Error: Object 00690D70 begin 666 test.d ""GT` ` end
Jul 04 2002
parent reply Burton Radons <loth users.sourceforge.net> writes:
Dario wrote:

(This surely has been already told. I remember I have read about it
somewhere, but I don't remember where... I apologize.)
We discussed it a few weeks ago, but your problem is new.
What's the D sintax for RTTI? I tried
if(instance.typeinfo === Class.typeinfo) {/*...*/}
but this doesn't work. I tried
if(instance.classinfo === Class.classinfo) {/*...*/}
but this generates an internal error.
This is correct and should work.  Could you boil it down to the smallest
amount of code that can cause the internal error and then post that?
This compiles good but emits a runtime error: Error: Object 00690D70
All references are initialised to null, so you're dereferencing a null pointer there. Putting a "a = new AAA;" before that line should make it work, although you may need to add a constructor.
Jul 04 2002
parent "Dario" <supdar yahoo.com> writes:
ARGH! I'm so stupid that I forgot that! Thank you Burton! =]
Dario
Jul 04 2002