为什么我不能使operator ++()nothrow?
这可能是使用postfix ++运算符(通过前缀++运算符)的少数几个优点之一.
例如,此代码无法编译
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;
};
Run Code Online (Sandbox Code Playgroud)
另外注意,后缀运算符也可以是线程安全的.
| 归档时间: |
|
| 查看次数: |
158 次 |
| 最近记录: |