On 2012-02-04 14:45, Simen Kjærås wrote:
Like bearophile said, Point(x, y) should work - assuming you have
defined no other constructors for Point.

You are correct, my apologies for not testing more thoroughly.
Let me try again, explaining the real issue:
I have 3 files:
-- Bar.d --
import Foo;
import Struct;
class Bar {
  Foo _foo;
  this() {
    _foo = new Foo(Struct(1));
  }
}
void main() {
  new Bar();
}

-- Foo.d --
import Struct;
class Foo {
  Struct _s;
  this(Struct s) {
    _s = s;
  }
}

-- Struct.d --
struct Struct {
  int baz;
}

This code does not compile:
Bar.d:6: Error: function expected before (), not module Struct of type void
Bar.d:6: Error: constructor Foo.Foo.this (Struct s) is not callable using argument types (_error_)

Why is that?


It is. The problem is that bool opEquals(ref const Point) expects a Point
by reference, and the return value from your property is a temporary, from
which we can get no reference. The solution is to remove the ref:
bool opEquals(const Point). The only reason to use ref here is to cut down
on copying, and might be worthwhile on larger structures.

I've tried removing the "ref", but I get other errors in return then:
Point.d:19: Error: function Point.Point.opEquals type signature should be const bool(ref const(Point)) not const bool(const const(Point) p) Coordinate.d:20: Error: function Coordinate.Coordinate.opEquals type signature should be const bool(ref const(Coordinate)) not const bool(const const(Coordinate) c)

Reply via email to