[英]operator++() nothrow does not compile
Why can't I make operator++() nothrow? 为什么我不能使operator ++()无效?
This could be one of the few advantages of using the postfix ++ operator (over the prefix ++ operator). 这可能是使用后缀++运算符(超过前缀++运算符)的少数优点之一。
For example, this code does not compile 例如,此代码无法编译
class Number
{
public:
Number& operator++ () // ++ prefix
{
++m_c;
return *this;
}
Number operator++ (int) nothrow // postfix ++
{
Number result(*this); // make a copy for result
++(*this); // Now use the prefix version to do the work
return result; // return the copy (the old) value.
}
int m_c;
};
On a side note it the postfix operator could also be made thread-safe. 附带说明一下,postfix运算符也可以设置为线程安全的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.