Translate C++ to D

Jason House jason.james.house at gmail.com
Tue Jan 8 12:15:45 PST 2008


Luca Lupo Wrote:

> Someone known convert this c++ code to D?
> 
> TANKS SO MUCH

Below is my cut at it.  Note that I made a few assumptions that may or may not be correct for you.  I used a singly linked list from the phobos library instead of std.list.  Also, I don't know what Observer and Post are.  I don't know what the right way to use them are.  For example, if Observer is a class, there's no need to use Observer*.  Also, I don't know if Post is getting copied when passed into the newPost function.  Depending on what's going on there, that function signature may need to change


import std.slist;
import Observer;
import Post;

class Subject{
       private:
       public:
               // Functions are virtual by default
               Slist!(Observer *) _observer; // Observer or Observer*?
               ~Subject();
               void Attach(Observer *); // Observer or Observer*?
               void Detach(Observer *); // Observer or Observer*?
               void Notify();  
       protected:
               this();
       }

class Blog : public Subject{
       private:
               string Blog_name;
               Slist!(Post) l_post;
       public:
               // If no overloading by derived classes, 
               // compiler will make non-virtual
              Blog(string );
              void Notify(); 
              void NewPost(Post); // Post? const Post? in Post?
              string GetName();
              void print();
       };



More information about the Digitalmars-d mailing list