digitalmars.D - Where does the classinfo property come from?
- Chuck.Esterbrook /at/ gmail /dot/ com (12/12) Aug 15 2005 The following wiki page shows that you can say "someObj.classinfo.name":
- Ben Hinkle (11/27) Aug 15 2005 "Chuck.Esterbrook /at/ gmail /dot/ com"
The following wiki page shows that you can say "someObj.classinfo.name": http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/RealtimeTypeInformation I verified this, but I'm wondering where it comes from? I don't recall reading about the "classinfo" property in the language docs. I checked Object in the Phobos docs and it's not there. I checked the definition of Object { } in Object.d and it has no "classinfo". There *is* a "classinfo" in struct Interface, but I don't see how that would be connected. What is the connection that allows the D compiler to get from "someObj" to "classinfo"? How come I don't see it in Object { ... } in Object.d as a field or function? Thanks in advance, -Chuck
Aug 15 2005
"Chuck.Esterbrook /at/ gmail /dot/ com" <Chuck.Esterbrook_member pathlink.com> wrote in message news:ddpii5$e0a$1 digitaldaemon.com...The following wiki page shows that you can say "someObj.classinfo.name": http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/RealtimeTypeInformation I verified this, but I'm wondering where it comes from? I don't recall reading about the "classinfo" property in the language docs. I checked Object in the Phobos docs and it's not there. I checked the definition of Object { } in Object.d and it has no "classinfo". There *is* a "classinfo" in struct Interface, but I don't see how that would be connected.ClassInfo should be documented but isn't. I also thought TypeInfo was defined somewhere but it isn't either.What is the connection that allows the D compiler to get from "someObj" to "classinfo"?When you define a class the compiler builds a ClassInfo instance and serializes it to the obj file. When you say "someObj.classinfo" you get a reference to that static ClassInfo instance.How come I don't see it in Object { ... } in Object.d as a field or function?The compiler has a special check for it. At runtime the pointer to the classinfo is stored in the first slot of the vtable (it needs to be obtainable from the object ref in order to support RTTI).Thanks in advance, -Chuck
Aug 15 2005