Get the class name without casting the type

Imperatorn johan_forsberg_86 at hotmail.com
Tue Nov 15 14:26:22 UTC 2022


On Tuesday, 15 November 2022 at 12:25:22 UTC, Hipreme wrote:
> On Tuesday, 15 November 2022 at 11:42:59 UTC, Alexander Zhirov 
> wrote:

As shown you can use Object for this.

Side-note, you don't override interface members, you implement 
them.

```d
         interface A
         {
             string text();
         }

         class B : A
         {
             string text()
             {
                 return ": To B or not to B!";
             }
         }

         class C : A
         {
             string text()
             {
                 return ": Oh I C!";
             }
         }

         void main()
         {
             Object[] a = new B[3];
             B b = new B();
             C c = new C();

             fill(a, b);

             //Just to show
             a[0] = c;

             foreach (val; a)
             {
                 writeln(typeof(val).stringof, val.text());
             }
         }
```


More information about the Digitalmars-d-learn mailing list