Quantcast
Channel: User CPlus - Programming Language Design and Implementation Stack Exchange
Viewing all articles
Browse latest Browse all 65

What alternatives are there for C++ operator overloading syntax?

$
0
0

I noticed C++ has operator overloading syntax with just the operator names:

T& operator +(T& lhs, T& rhs) {    return /* ... */;}

However, there are 2 distinct operators that are both ++ and --. One being a suffix and one being a prefix. C++ syntax has no way to distinguish them with the syntax, so instead one of them uses an unused int parameter. But this seems ungraceful.

What would be a good alternative syntax for operator overloading that could unambiguously distinguish unary + with binary + and also distinguish ++x from x++ without hacks such as unused parameters?


Viewing all articles
Browse latest Browse all 65

Trending Articles