gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 16:15:27 25 4
gpt4 key购买 nike

C++1y/C++14 标准中的哪个地方说以下翻译单元格式错误?

struct S {};

void operator+(S,S,S);

错误是:

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 x.operator@() or operator@(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 @, x@y can be interpreted as either x.operator@(y) or operator@(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.

关于C++14/1y : Standard ref for "operator+ must take either one or two arguments"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com