daniel1426
daniel1426

Reputation: 169

Haxe operator overloading

How can I accomplish operator overloading in a way that is convenient to use?

enter image description here

As you can see, putting an operator overload in a class does nothing. Also, if I use "abstract", I can't even call the Bark() method on Dog.
Operator overloading shouldn't be so convoluted and unviable.

Upvotes: 0

Views: 1890

Answers (2)

profound7
profound7

Reputation: 21

In haxe 3.1.3, you can add @:forward before the abstract to forward underlying attributes and methods to the abstract.

@:forward // add this!
abstract Dog2(Dog) to Dog from Dog
{
    ...
}

new Dog2().Bark(); // no more error!

You can also forward specific methods/attributes to the abstract. See Forwarding abstract fields

Upvotes: 2

Franco Ponticelli
Franco Ponticelli

Reputation: 4430

Operator overloading is only for abstracts at the moment. What you can do is to create and to apply a macro to your context (where your operations are executed) and transform the expression tree so that the operations are mapped to the right methods.

Upvotes: 2

Related Questions