what is the different bettwen typeid and .classinfo?
Steven Schveighoffer
schveiguy at gmail.com
Mon Mar 30 15:15:08 UTC 2020
On 3/30/20 10:38 AM, lilijreey wrote:
> Hi:
> I write code like this
> ```D
> class Base
> {
> int base;
> }
>
> class CC :Base
> {
> int cc;
> }
>
> auto cc = new CC;
>
> //I want check cc object type is CC
> if (typeid(cc) == typeid(CC)) // ok ==
>
> if (cc.classinfo == AstAssignNode) //error
>
> if (cc.classinfo == AstAssignNode.classinfo) // ok ==
> ```
They are both the same. Historically they were different (ClassInfo was
its own type different from TypeInfo_Class). I would recommend typeid
for future-proof code (it's possible, however unlikely, that .classinfo
at some point goes away).
-Steve
More information about the Digitalmars-d-learn
mailing list