On page 344 of "Programming in D", we have this snippet:
```
 TypeInfo_Class info = a.classinfo;
 string runtimeTypeName = info.name;
```

I've expanded it to source/app.d which when runs produces output:
```
app.Violin
app.Guitar

app.Violin
TypeInfo_Class
object.TypeInfo
```

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;

    writeln(v2);
    writeln(className);
    writeln(baseName);
}

MusicalInstrument foo(int i) {
    return (i % 2) ? new Violin() : new Guitar();
}

class MusicalInstrument {
}

class StringInstrument : MusicalInstrument {
}

class Violin : StringInstrument {
}

class Guitar : StringInstrument {
}

```
  • TypeInfo_Class c... Brother Bill via Digitalmars-d-learn

Reply via email to