Re: Get the class name without casting the type

2022-11-15 Thread Alexander Zhirov via Digitalmars-d-learn
On Tuesday, 15 November 2022 at 14:26:22 UTC, Imperatorn wrote: Side-note, you don't override interface members, you implement them. My knowledge of D is still modest, most likely, I just didn't know that override with interfaces can not be used. Thanks for the hint!

Re: Get the class name without casting the type

2022-11-15 Thread Alexander Zhirov via Digitalmars-d-learn
On Tuesday, 15 November 2022 at 14:09:01 UTC, bauss wrote: If you cast to Object and use classinfo.name then you get the expected result of B. Thanks! 😌

Re: Get the class name without casting the type

2022-11-15 Thread Imperatorn via Digitalmars-d-learn
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

Re: Get the class name without casting the type

2022-11-15 Thread bauss via Digitalmars-d-learn
On Tuesday, 15 November 2022 at 11:42:59 UTC, Alexander Zhirov wrote: Is there any way to get the name of class B? ```d interface A { string text(); } class B : A { override string text() { return ": It's ok!"; } } void main() { A[] a = cast(A[]) new B[3]; B b = new

Re: Get the class name without casting the type

2022-11-15 Thread Hipreme via Digitalmars-d-learn
On Tuesday, 15 November 2022 at 11:42:59 UTC, Alexander Zhirov wrote: Is there any way to get the name of class B? ```d interface A { string text(); } class B : A { override string text() { return ": It's ok!"; } } void main() { A[] a = cast(A[]) new B[3]; B b = new

Re: Get the class name without casting the type

2022-11-15 Thread Alexander Zhirov via Digitalmars-d-learn
On Tuesday, 15 November 2022 at 12:25:22 UTC, Hipreme wrote: You can do it as `val.classinfo.name` Yes, I have already done so, but the result is the same, actually :) ```d app.A: It's ok! app.A: It's ok! app.A: It's ok! ```

Get the class name without casting the type

2022-11-15 Thread Alexander Zhirov via Digitalmars-d-learn
Is there any way to get the name of class B? ```d interface A { string text(); } class B : A { override string text() { return ": It's ok!"; } } void main() { A[] a = cast(A[]) new B[3]; B b = new B(); fill(a, b); foreach (val ; a) { writeln(typeof(va