[英]operator++() nothrow does not compile
為什么我不能使operator ++()無效?
這可能是使用后綴++運算符(超過前綴++運算符)的少數優點之一。
例如,此代碼無法編譯
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;
};
附帶說明一下,postfix運算符也可以設置為線程安全的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.