Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.
Version 2 (modified by nascent, 11 years ago)
Updated to be version agnostic.

Runtime Type Information (RTTI)

Part of TutorialIntermediate

Description

You can find out some class information during runtime.

Example

import std.stdio;

class A {}

int main ( char [] [] args ) 
{
    A a = new A;
    Object o;
    o = new Object;
    bool b;
    
    writef("%s\n", a.classinfo.name);
    writef("%s\n", o.classinfo.name);

    /* These aren't allowed... */

//    writef("%s\n", b.classinfo.name);
//    writef("%s\n", b.typeinfo.name);

    return 1;
}

More Information

See also:

Source

Link http://www.dsource.org/tutorials/index.php?show_example=34
Posted by jcc7
Date/Time Mon May 3, 2004 12:18 am