what is the different bettwen typeid and .classinfo?

Pham home at home.com
Mon Mar 30 17:06:09 UTC 2020


On Monday, 30 March 2020 at 15:15:08 UTC, Steven Schveighoffer 
wrote:
> 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

Will it be the same if using "is", the reason is for function 
that use "nothrow" attribute?
if (cc.classinfo is typeid(CC))




More information about the Digitalmars-d-learn mailing list