Error: variable foo forward referenced

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 6 22:54:18 PDT 2017


Why does this:

enum AddrSpace {
     Global,Shared
}

struct Pointer(AddrSpace as, T)
{
     T* ptr;
     alias ptr this;
}
struct AutoIndexed(T) if (is(T : Pointer!(n,U),AddrSpace n,U))
{
     T p;

     private @property auto idx()
     {
         static if (n == AddrSpace.Global)
             return GlobalIndex.linear;
         else static if (n == AddrSpace.Shared)
             return SharedIndex.linear;
         else
             static assert(0, "can only auto index a GlobalPointer 
or SharedPointer");
     }

     @property U index()
     {
         return p[idx];
     }

     @property void index(U t)
     {
         p[idx] = t;
     }
}

give

Error: variable p forward referenced

halfway though MY semantic pass????

I've tried
is(T == Pointer!(n,U),AddrSpace n,U)
is(T : Pointer!(n,U), n,U)
and a bunch of other combos.
Why am I getting this and how do I get rid of it?


More information about the Digitalmars-d-learn mailing list