簡體   English   中英

operator ++()nothrow無法編譯

[英]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運算符也可以設置為線程安全的。

nothrow是一個常量,用於傳遞給new運算符,以指示new不應在出錯時引發異常。

我想你想要的就是什么

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM