typeid() woes
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sun Aug 8 15:02:41 PDT 2010
I need to be a little patient. :) On the next page it explains the static
vs. dynamic type, so I guess typeid() always returns the dynamic type. I
wonder if there's a way to get the static type, is there an equivalent
function like typeid() for such a case?
On Sun, Aug 8, 2010 at 11:57 PM, Andrej Mitrovic <andrej.mitrovich at gmail.com
> wrote:
> 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?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100809/ede0129c/attachment.html>
More information about the Digitalmars-d
mailing list