TypeInfo_Class confusion

Brother Bill brotherbill at mail.com
Sun Aug 10 11:32:09 UTC 2025


On Sunday, 10 August 2025 at 10:07:13 UTC, user1234 wrote:
> On Sunday, 10 August 2025 at 09:58:50 UTC, user1234 wrote:
>> On Saturday, 9 August 2025 at 11:13:42 UTC, Brother Bill wrote:
>>> On page 344 of "Programming in D", we have this snippet:
>>> [...]
>>> I was expecting something more concrete than TypeInfo_Class 
>>> or object.TypeInfo, such as "Violin" or "StringInstrument".
>>>
>>> Am I missing something or have I made a mistake?
>>>
>>> source/app.d
>>> ```
>>> import std.stdio;
>>>
>>> void main() {
>>>     TypeInfo v = typeid(foo(1));
>>>     TypeInfo g = typeid(foo(2));
>>>
>>>     assert(v != g); // ← the two types are not the same
>>>
>>>     writeln(v);
>>>     writeln(g);
>>>     writeln;
>>>
>>>     TypeInfo_Class v2 = typeid(foo(1));
>>>     string className = v2.classinfo.name;
>>>     string baseName = v2.classinfo.base.name;
>>
>>
>> Change the last lines to
>>
>> ```d
>> string className = v2.name;
>> string baseName = v2.base.name;
>> ```
>>
>> otherwise you operates on the TypeInfo_Class of the Type_Info 
>> class **itself**.
>
> forgot to say... the confusion comes from the fact that 
> `typeid(a).classinfo` is actually the same as 
> `typeid(typeid(a))`. IIRC it was planned to remove `.classinfo` 
> because of that lack of orthogonality.

Bingo!  That's it.  Thank you.



More information about the Digitalmars-d-learn mailing list