Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a prefix operator

Suppose I have this class:

class Int{
    private:
        int x;
    public:
        Int(int i) : x(i) {}
};

Can I build a prefix + operator to write expression such x = + a b?

I tried to overload operator+ inside the class but the compiler complain that operator+ must be unary or binary and not ternary.

Is there a way to do such thing?

like image 566
Aslan986 Avatar asked Aug 14 '26 09:08

Aslan986


1 Answers

No you can't change the basic syntax of the expression.

like image 95
Naveen Avatar answered Aug 16 '26 23:08

Naveen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!