Re: Nested Classes with inheritance

2022-03-20 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 20 March 2022 at 05:44:44 UTC, Salih Dincer wrote: On Sunday, 20 March 2022 at 01:28:44 UTC, Era Scarecrow wrote: Inheritance and Polymorphism is one of the hardest things to grasp mostly because examples they give in other books of 'objects' is so far unrelated to software that it d

Re: Nested Classes with inheritance

2022-03-19 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 20 March 2022 at 01:28:44 UTC, Era Scarecrow wrote: Inheritance and Polymorphism is one of the hardest things to grasp mostly because examples they give in other books of 'objects' is so far unrelated to software that it doesn't really compare. `"An object is like a book which you ca

Re: Nested Classes with inheritance

2022-03-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 19 March 2022 at 12:23:02 UTC, user1234 wrote: I think OP is learning OOP. His error looks like that for the least. True. Looking at the code it shouldn't spaghetti in on itself infinitely and is basically clean in his intent. Inheritance and Polymorphism is one of the hardest

Re: Nested Classes with inheritance

2022-03-19 Thread user1234 via Digitalmars-d-learn
On Saturday, 19 March 2022 at 05:25:01 UTC, Era Scarecrow wrote: On Saturday, 19 March 2022 at 00:16:48 UTC, user1234 wrote: That crashes because of the creation of `Bar b` member, which itself has a Bar b member, which itself... Mhmm... So There's Foo with Bar b, which has Bar b which has B

Re: Nested Classes with inheritance

2022-03-19 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 19 March 2022 at 00:16:48 UTC, user1234 wrote: ```d if (typeid(this) !is typeid(Bar)) this.b = new Bar(this.i); ``` A very clever and ingenious solution. Thanks... SDB@79

Re: Nested Classes with inheritance

2022-03-18 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 19 March 2022 at 00:16:48 UTC, user1234 wrote: That crashes because of the creation of `Bar b` member, which itself has a Bar b member, which itself... Mhmm... So There's Foo with Bar b, which has Bar b which has Bar b which... just keeps going over and over again. It appears

Re: Nested Classes with inheritance

2022-03-18 Thread user1234 via Digitalmars-d-learn
On Saturday, 19 March 2022 at 00:05:54 UTC, Salih Dincer wrote: Greetings to all... There are nested classes as below. But beware, there's also inheritance, extra! If you construct ```Bar b``` from main(), it's okay. But if declare the constructor in Foo(), the program crashes with a segmenta

Nested Classes with inheritance

2022-03-18 Thread Salih Dincer via Digitalmars-d-learn
Greetings to all... There are nested classes as below. But beware, there's also inheritance, extra! If you construct ```Bar b``` from main(), it's okay. But if declare the constructor in Foo(), the program crashes with a segmentation error. Is this not legal? Like two mirrors are facing each