idup class

Joshua Niehus via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 16 13:28:41 PDT 2014


trying to follow:
http://ddili.org/ders/d.en/class.html

//--- OSX 10.9 DMD 2.065
module test;

class Foo {
      int num;

      this(int num) {
          this.num = num;
      }

      Foo dup() const {
          return new Foo(this.num);
      }

      immutable(Foo) idup() const {
          return new immutable(Foo)(this.num);
      }
}

void main() {
      auto  foo = new Foo(1);
      auto mfoo = foo.dup();
      auto ifoo = foo.idup();
}

* test.d(15): Error: mutable method test.Foo.this is not callable
using a immutable object
* test.d(15): Error: no constructor for Foo
* Failed: ["dmd", "-v", "-o-", "test.d", "-I."]
//---

What am i missing?


More information about the Digitalmars-d-learn mailing list