I have a small program like below. Everything works as it should in classes; even if I call the structure with the new operator. But if I stop using classes, scope doesn't work properly!

```d
class/* STEP2
struct//*/
Foo {
  this(int i) {
    i.writefln!"Object %s is created...";
  }
  ~this() {
  writeln("Object was deleted!");
  }
}

import std.stdio;
void main() {
   write("call ");
   writeln("return ", loop);
}

auto loop() {
  enum func = __FUNCTION__;
  func.writeln;

  for (auto i = 1; i != 3; ++i) {
    scope // STEP1
    auto foo = new Foo(i);
  }
  return func;
}

```

Please put a comment (//) mark at the beginning of the line that says STEP1 and then STEP2. Then change STEP1 back to its previous state, that is, enable the scope. You will sense that something is wrong...

Why doesn't it work correctly in structs?
Or is scope the default in structs?

SDB@79
  • Scope & Stru... Salih Dincer via Digitalmars-d-learn
    • Re: Scope &... Salih Dincer via Digitalmars-d-learn
      • Re: Sco... Nick Treleaven via Digitalmars-d-learn
        • Re:... Salih Dincer via Digitalmars-d-learn
          • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Scope &... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Sco... Salih Dincer via Digitalmars-d-learn
        • Re:... Nick Treleaven via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... Salih Dincer via Digitalmars-d-learn

Reply via email to