// The following operator++() represents overloading of pre-increment
MyIncrDecrClass& operator++()
{
++this->m_nCounter;
return *this;
}
// Passing dummy int argument is to mention overloading of post-increment
MyIncrDecrClass& operator++(int)
{
this->m_nCounter++;
return *this;
}
因此,這是怎樣一個崗位和預增操作符來實現,但對我來說,我不能真正實現它這樣的,所以這是我做過什麼:後增量重載中的冗餘?
VLongInt& VLongInt::operator++()
{
... //BUILD TEMP vector
this->vec = temp;
return *this;
}
VLongInt& VLongInt::operator++(int)
{
this->vec = this.vec; //seems unnecessary
... //BUILD TEMP vector
this->vec = temp
return *this;
}
這有什麼錯?看起來兩者應該以同樣的方式實施。只有頭文件應該不同,對吧?
這聽起來像你的代碼的工作,你只是想知道,如果你寫的是錯誤的。這可能更適合http://codereview.stackexchange.com/ –
這一切都取決於您希望增量操作員爲您的班級表示什麼。但它看起來對我來說是錯誤的 - 無論哪種方式你的論點都應該修改 - 但是在一種情況下,你應該返回原始的,而不是修改後的版本。而且你不區分功能簽名 - 這甚至編譯? – Floris
在第二個代碼塊中,您編寫了兩個具有相同名稱,返回類型和參數的函數。也許我對C++不夠了解,但編譯器應該如何區分這兩個定義? –