Re: How to get child class Type and members from parent class?

2019-11-21 Thread zoujiaqing via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 22:26:17 UTC, Adam D. Ruppe wrote: On Wednesday, 20 November 2019 at 20:57:56 UTC, Matheus wrote: This is a different way of designing things, do people use this often? This is really only useful sometimes. It is important to notice that if you do class C :

Re: How to get child class Type and members from parent class?

2019-11-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 20:57:56 UTC, Matheus wrote: This is a different way of designing things, do people use this often? This is really only useful sometimes. It is important to notice that if you do class C : I {} I c = new C(); c.something(); the template this there will

Re: How to get child class Type and members from parent class?

2019-11-20 Thread Matheus via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 13:46:07 UTC, Jacob Carlborg wrote: On Wednesday, 20 November 2019 at 10:05:11 UTC, zoujiaqing wrote: import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); } } class B :

Re: How to get child class Type and members from parent class?

2019-11-20 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 10:05:11 UTC, zoujiaqing wrote: import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); } } class B : A { string v = "hello"; } void main() { auto b = new B;

Re: How to get child class Type and members from parent class?

2019-11-20 Thread mipri via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 10:05:11 UTC, zoujiaqing wrote: import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); Here, class A knows that a 'v' member is present. So why not just put that member in

How to get child class Type and members from parent class?

2019-11-20 Thread zoujiaqing via Digitalmars-d-learn
import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); } } class B : A { string v = "hello"; } void main() { auto b = new B; writeln(b.write()); // print hello }