当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - C++14/1y: Standard ref for "operator+ must take either one or two arguments"?

问题描述:

Where in the C++1y/C++14 standard does it say that the following translation unit is ill-formed?

struct S {};

void operator+(S,S,S);

The error is:

error: ‘void operator+(S, S, S)’ must take either one or two arguments

网友答案:

[over.unary]

1 A prefix unary operator shall be implemented by a non-static member function (9.3) with no parameters or a non-member function with one parameter. Thus, for any prefix unary operator @, @x can be interpreted as either [email protected]() or [email protected](x). If both forms of the operator function have been declared, the rules in 13.3.1.2 determine which, if any, interpretation is used. See 13.5.7 for an explanation of the postfix unary operators ++ and --.

[over.binary]

1 A binary operator shall be implemented either by a non-static member function (9.3) with one parameter or by a non-member function with two parameters. Thus, for any binary operator @, [email protected] can be interpreted as either [email protected](y) or [email protected](x,y). If both forms of the operator function have been declared, the rules in 13.3.1.2 determine which, if any, interpretation is used.

分享给朋友:
您可能感兴趣的文章:
随机阅读: