Re: Passing a derived class where base class is defined as ref parameter

2021-12-14 Thread chopchop via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 20:58:21 UTC, Adam D Ruppe wrote: nice. You might want to look at my terminal.d (arsd-official:terminal on dub) too which has pretty comprehensive functionality for tons of things. Prolly more than you need looking at your interface tho but it includes the outpu

Re: Passing a derived class where base class is defined as ref parameter

2021-12-14 Thread chopchop via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 17:27:13 UTC, Stanislav Blinov wrote: Simple. Don't take a `ref`. Just take a `Console`. Classes in D are reference types, you're not making a copy as you would in C++ if you were to write `updateFoodToken(Console c)`. Ah, ok, Reference types! That's great. Defi

Re: Passing a derived class where base class is defined as ref parameter

2021-12-14 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 17:20:18 UTC, chopchop wrote: I am using the "ref" here (I put tinyurl to avoid over-referencing the post instead of the github page itself): https://tinyurl.com/bdddkmub yeah D classes are automatically ref unlike c++ so you don't need the second level of it m

Re: Passing a derived class where base class is defined as ref parameter

2021-12-14 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 17:20:18 UTC, chopchop wrote: I am using the "ref" here (I put tinyurl to avoid over-referencing the post instead of the github page itself): https://tinyurl.com/bdddkmub I would like to be able to pass any kind of console to updateFoodToken ( Console c ), ie e

Re: Passing a derived class where base class is defined as ref parameter

2021-12-14 Thread chopchop via Digitalmars-d-learn
On Monday, 13 December 2021 at 22:30:59 UTC, Adam D Ruppe wrote: On Monday, 13 December 2021 at 22:06:45 UTC, chopchop wrote: If I remove the ref, it works as expected, that is to say I can give a derived class as parameter. Why are you using the ref to begin with? What the logic here? Con

Re: Passing a derived class where base class is defined as ref parameter

2021-12-14 Thread chopchop via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 05:38:17 UTC, Tejas wrote: On Monday, 13 December 2021 at 22:30:59 UTC, Adam D Ruppe wrote: On Monday, 13 December 2021 at 22:06:45 UTC, chopchop wrote: If I remove the ref, it works as expected, that is to say I can give a derived class as parameter. Why are y

Re: Passing a derived class where base class is defined as ref parameter

2021-12-13 Thread Mike Parker via Digitalmars-d-learn
On Monday, 13 December 2021 at 22:06:45 UTC, chopchop wrote: If I remove the ref, it works as expected, that is to say I can give a derived class as parameter. I have an idea why it does not work, but I think a c++ reference would work, ie incr(A& console) would accept a B as parameter. What t

Re: Passing a derived class where base class is defined as ref parameter

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Monday, 13 December 2021 at 22:30:59 UTC, Adam D Ruppe wrote: On Monday, 13 December 2021 at 22:06:45 UTC, chopchop wrote: If I remove the ref, it works as expected, that is to say I can give a derived class as parameter. Why are you using the ref to begin with? What the logic here? Con

Re: Passing a derived class where base class is defined as ref parameter

2021-12-13 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 13 December 2021 at 22:06:45 UTC, chopchop wrote: If I remove the ref, it works as expected, that is to say I can give a derived class as parameter. Why are you using the ref to begin with? What the logic here? Consider this: class C : A {} void incr(ref A a) { a = new C; }

Passing a derived class where base class is defined as ref parameter

2021-12-13 Thread chopchop via Digitalmars-d-learn
Hi guys, below a small piece of code, which does not compile because "b" of type B can not be passed as ref parameter to incr(ref A a). If I remove the ref, it works as expected, that is to say I can give a derived class as parameter. I have an idea why it does not work, but I think a c++ re