On 05/27/2010 03:47 PM, Jason House wrote:

In module b, delete the import of c. In module c, delete the import of b. Your sample code will then compile and run. It probably wouldn't do what you want though; you'll have two globals
(b.foo and c.foo).  I suspect what you really want is one global a.foo?

Two distinct globals. There is a more concrete example:

module QObject;

class QMetaObject
{
    ...
}

mixin template Q_OBJECT()
{
    ...

    immutable(QMetaObject) metaObject() immutable
    {
        return staticMetaObject;
    }

    static immutable QMetaObject staticMetaObject;
    shared static this()
    {
staticMetaObject = cast(immutable)QMetaObject.create!(typeof(this));
    }
}

----
module a;
import QObject;
import b;

class A : QObject
{
    B b;
    mixin Q_OBJECT;
}

----
module b;
import QObject;
import a;

class B :
{
    A a;
    mixin Q_OBJECT;
}

When mixed in a class, Q_OBJECT, among other things, associates a global RTTI object with that class. Ideally, this object should be created at program startup.

We cannot impose on the user of Q_OBJECT the requirement that a and b should not be circularly imported or that he has to manually call an initialization function etc.

Reply via email to