Classes. C++ to D

QAston via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 3 13:02:59 PDT 2015


On Sunday, 3 May 2015 at 17:35:42 UTC, Dennis Ritchie wrote:
> Hi,
> How can I rewrite this code to the D?
>
> -----
> #include <string>
> #include <iostream>
>
> class A {
>      public:
>      std::string a() {
>          return std::string("foo");
>      }
> };
>
> class B {
>      public:
>      std::string b(){
>          return std::string("bar");
>      }
> };
>
> class C : public A, public B {};
>
> int main () {
>
>      C c;
>
>      std::cout << c.a() << c.b() << std::endl;
>
>      return 0;
> }

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.


More information about the Digitalmars-d-learn mailing list