c++ - 除了++ 和 -- 之外,是否可以重载后缀一元运算符?

标签 c++ overloading operator-keyword

在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/

相关文章:

swift - Swift 初始化的三元运算符

c++ - 比较运算符值 C++

c++ - 声明一个模板函数,它接收两个通用迭代器作为参数

c++ - 命名互斥体的不同句柄结果

c++ - 基类重载方法,默认成员变量

c# - C#中对象的碰撞检测

C# 运算符重载、重写字符串?

c# - 哪个更快 - C# 不安全代码或原始 C++

c++ - boost::make_zip_iterator 的 decltype?

c++ 函数重载,使 fwrite/fread 的行为像 PHP 版本