Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

In what section does it mention I cannot define an operator such as `int operator(char, int)' ?

30 views
Skip to first unread message

Shiyao Ma

unread,
Nov 6, 2016, 1:08:31 AM11/6/16
to
Overloading operator without at least a single param of enum of class type is forbidden, but where in the standard says so?

Put in to other words, defining `int operator(char, int)' violates what rule in the standard?

I need someone to refer to me the exact paragraph in the standard.


Thanks.

Alf P. Steinbach

unread,
Nov 6, 2016, 3:46:27 AM11/6/16
to
On 06.11.2016 07:08, Shiyao Ma wrote:
> Overloading operator without at least a single param of enum [or] class
> type is forbidden, but where in the standard says so?

C++11 §13.5/6 (over.oper/6): “An operator function shall either be a
non-static member function or be a non-member function and have at least
one parameter whose type is a class, a reference to a class, an
enumeration, or a reference to an enumeration”


> Put in to other words, defining `int operator(char, int)' violates
> what rule in the standard?
>
> I need someone to refer to me the exact paragraph in the standard.

You'll get more familiar with it over time.

But it is one heck of an inaccessible document. ;-)


Cheers & hth.,

- Alf


j...@slashslash.info

unread,
Nov 6, 2016, 8:00:37 PM11/6/16
to
Interesting. It seems that you could define:

std::string operator-(std::string const&, std::string const&);

I had assumed that doing so would be forbidden. I guess it wouldn't break any existing code.

0 new messages