Hi guys,
here's my full code below.
My problem is that last "auto Y = X" assignment, that the compiler won't accept:

yo.globalFunction.DirectStruct.IndirectStruct.indirectMemberFunc cannot access frame of function yo.globalFunction

I was expecting X to be accessible from here.
Suprisingly, if I replace all "struct" with "class", the last assignment is accepted by the compiler. Could someone please tell me why the scoping asymmetry between structs and classes?

void globalFunction()
{
  auto X = 0;

  struct DirectStruct
  {
    void directMemberFunc()
    {
      auto Y = X; // OK, X is accessible

      struct HybridStruct
      {
        void hybridFunc()
        {
          auto Y = X; // OK, X is accessible
        }
      }
    }

    struct IndirectStruct
    {
      void indirectMemberFunc()
      {
        auto Y = X; // Error: can't access frame of globalFunc
      }
    }
  }
}


  • Accessing function frame from st... Sebastien Alaiwan via Digitalmars-d-learn

Reply via email to