Imcompatible type, const and const
bearophile
bearophileHUGS at lycos.com
Sun Mar 9 09:34:05 PDT 2014
Duarte:
> What am I missing here? The same code in C++ compile, so I was
> assuming it would just as well compile in D.
C++ and D are two different languages, and among other things
they have two very different constant-ness systems, so code in
one language often can't work in the other.
In your code probably there are multiple problems. One problem I
see is here:
Vector2 opBinary(string op)(const Point2 _right) {
static if(op == "-") {
return new Vector2(this.x - _right.x, this.y -
_right.y);
}
}
You have to use a template constraint otherwise one of your code
paths returns nothing, and this is (thankfully) an error in D.
Also regarding your style, in D functions start with a lower case
letter.
I suggest to ask similar questions in the D.learn newsgroup.
Bye,
bearophile
More information about the Digitalmars-d-ide
mailing list