Re: Array of objects and their inheritance

2015-05-15 Thread tired_eyes via Digitalmars-d-learn
Thank you for the explanation

Re: Array of objects and their inheritance

2015-05-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 14 May 2015 at 19:00:16 UTC, tired_eyes wrote: First, I don't understand why we see array[2] as 'Child'. While it is a 'Child', shouldn't it be shown as a 'Parent' due to we explicitly create an array of 'Parents'? It is getting the name through a virtual interface (a hidden one

Array of objects and their inheritance

2015-05-14 Thread tired_eyes via Digitalmars-d-learn
Hi. I'm having a hard time understanding D's inheritance. Consider the following code: class Parent { public int x = 10; } class Child : Parent { public int y = 20; } void main() { import std.stdio; Parent[] array; auto obj1 = new Parent(); auto obj2 = new Child();