typeid() woes

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Aug 8 14:57:55 PDT 2010


test.d:

class Contact
{
}

class Friend : Contact
{    
    void reminder()
    {
        writeln("friend.reminder");
    }
}

unittest
{
    Contact c = new Friend; // c has type Contact but really refers to a Friend
    
    writeln(typeid(c));
    c.reminder();
}

This will not compile, as expected, since a Contact type doesn't have the reminder method.

But if I comment out the c.reminder() line, writeln will return "test.Friend". Why is that?


More information about the Digitalmars-d mailing list