How to turn this C++ into D?

Patrick Jeeves via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 5 09:17:08 PST 2014


So this is more a stackoverflow question, but I feel like later 
searchers will be more likely to find it if I put it here.

if I have the following C++ code:

class foo
{
static std::list<foo*> foo_list;
typedef std::list<foo*>::iterator iterator;
public:
     foo()
     {
        foo_list.push_back(this);
     }
     ~foo()
     {
        foo_list.remove(this);
     }

     static void DO_TASK()
     {
         for(iterator i = foo_list.begin(); i < foo_list.end(); 
++i)
         {
             (*i)->process();
         }

         for(iterator i = foo_list.begin(); i < foo_list.end(); 
++i)
         {
             (*i)->advance();
         }
     }

     virtual void process() = 0;
     virtual void advance() = 0;
}

How can I turn this into D?  Is there a way to register that 
static list with the garbage collector so it doesn't look into it 
or anything?

Similarly, I feel like this would be an interface in D, but 
interfaces don't have constructors.


More information about the Digitalmars-d-learn mailing list