Re: Why is this allowed? Inheritance variable shadowing

2021-05-26 Thread mw via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 18:58:47 UTC, JN wrote: On Tuesday, 13 August 2019 at 04:40:53 UTC, Chris Katko wrote: You can drop this straight into run.dlang.io: import std.stdio; class base{ float x=1;} class child : base {float x=2;} //shadows base variable! void main() { base

Re: Why is this allowed? Inheritance variable shadowing

2021-05-26 Thread sighoya via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 18:58:47 UTC, JN wrote: I am not buying the "C++ does it and it's legal there" argument. A point for it is the consistency with methods which also redefine super methods as default strategy. The question is if the default strategy needs to be changed? I wouldn't

Re: Why is this allowed? Inheritance variable shadowing

2021-05-26 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 18:58:47 UTC, JN wrote: Is there any viable usecase for this behavior? I am not buying the "C++ does it and it's legal there" argument. There's a reason most serious C++ projects use static analysis tools anyway. D should be better and protect against dangerous

Re: Why is this allowed? Inheritance variable shadowing

2021-05-26 Thread JN via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 04:40:53 UTC, Chris Katko wrote: You can drop this straight into run.dlang.io: import std.stdio; class base{ float x=1;} class child : base {float x=2;} //shadows base variable! void main() { base []array; child c = new child; array ~= c;

Re: Why is this allowed? Inheritance variable shadowing

2019-08-13 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 06:39:24 UTC, a11e99z wrote: On Tuesday, 13 August 2019 at 05:57:23 UTC, Mike Parker wrote: On Tuesday, 13 August 2019 at 04:40:53 UTC, Chris Katko wrote: OT: and again how to easy to google info about error/warning just with one word "CS0108" D can use attrs

Re: Why is this allowed? Inheritance variable shadowing

2019-08-13 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 05:57:23 UTC, Mike Parker wrote: On Tuesday, 13 August 2019 at 04:40:53 UTC, Chris Katko wrote: I don't know if I'd call that shadowing. This is how it works in Java, too. There's no such thing as a vtable for member variables -- each class gets its own set and

Re: Why is this allowed? Inheritance variable shadowing

2019-08-13 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 04:40:53 UTC, Chris Katko wrote: You can drop this straight into run.dlang.io: import std.stdio; class base{ float x=1;} class child : base {float x=2;} //shadows base variable! void main() { base []array; child c = new child; array ~= c;

Why is this allowed? Inheritance variable shadowing

2019-08-12 Thread Chris Katko via Digitalmars-d-learn
You can drop this straight into run.dlang.io: import std.stdio; class base{ float x=1;} class child : base {float x=2;} //shadows base variable! void main() { base []array; child c = new child; array ~= c; writeln(c.x); //=2 writeln(array[0].x); //=1 //uses BASE's