Classes. C++ to D

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 3 13:17:35 PDT 2015


On Sunday, 3 May 2015 at 17:46:54 UTC, Meta wrote:
> This is not really doable right now in D. You can forward the 
> function calls to a and b easily enough, but you can't inherit 
> from more than one class. Once the multiple alias this patch 
> gets merged you will be able to do this in D.

On Sunday, 3 May 2015 at 18:17:26 UTC, Adam D. Ruppe wrote:
> I'd make class A and class B into mixin templates instead.
>
> mixin template A {
>    string a() { return "foo"; }
> }
>
> mixin template B {
>    string b() { return "bar"; }
> }
>
> class C {
>    mixin A;
>    mixin B;
> }
>
> If you still need class A and class B, just make a class that 
> mixes in the template for them too.
>
>
> Since the C++ methods aren't virtual, I imagine you don't 
> really need a base class for them, but if you do want a virtual 
> base class, make interfaces and inherit from as many of them as 
> you need.

Thanks.

On Sunday, 3 May 2015 at 20:03:00 UTC, QAston wrote:
> If you want to learn a language properly, translating the idioms
> directly from what you already know is a bad approach. You're
> going to be frustrated that something was easy (to you) in your
> old language and the new one is weird and different than the old
> one. Also - results are often suboptimal.
>
> I've seen this happen too many times to not warn you, but if you
> just want to carry over and you don't care about learning or
> quality of result then please carry on.

At the moment, I do not do a complete study of the D, so the 
quality is not important to me. Start a complete study of D, I 
plan a little later.


More information about the Digitalmars-d-learn mailing list