在c++标准中说
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.
但是没有关于后缀运算符重载的一些信息。
最佳答案
关于后缀运算符 (13.5.7)
The user-defined function called operator++ implements the prefix and postfix ++ operator. If this function is a member function with no parameters, or a non-member function with one parameter of class or enumeration type, it defines the prefix increment operator ++ for objects of that type. If the function is a member function with one parameter (which shall be of type int) or a non-member function with two parameters (the second of which shall be of type int), it defines the postfix increment operator ++ for objects of that type. When the postfix increment is called as a result of using the ++ operator, the int argument will have value zero.
关于c++ - 除了++ 和 -- 之外,是否可以重载后缀一元运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23595984/