:スニペットは、このようなものです
circle& operator++(); // return by reference and this is prefix.
しかし、それはする必要がありますので、あなたは、接尾辞を使用します。
circle operator++ (int); // int is unused
署名を変更していますで十分ではありません。プレフィックスロジックを実装し、初期値を保存せずに値を直接変更するからです。だから、(c++).output()
のような結合された式であなたの実装にpostfix演算子を使用すると、期待される意味を尊重することはできません。ここで
バージョンの両方のimplemetnation:
circle& operator++() { // prefix
Area = Area * 2.0; // you can change directly the value
cout << "prefix"<<endl;
return *this; // and return the object which contains new value
}
circle operator++ (int) { // postfix
circle c(*this); // you must save current state
Area = Area * 2.0; // then you update the object
cout << "postfix"<<endl;
return c; // then you have to return the value before the operation
}
そして、ここで両者の差を表示するonline demo。
postfixバージョン 'c1 ++'はあなたが呼び出していませんか? – EdChum
また、あなたのバージョンが – EdChum
と一致していないので、あなたの[署名](http://en.cppreference.com/w/cpp/language/operator_incdec)をチェックする必要があります。ポストインクリメント 'c1 ++'の署名では、円と円::演算子++(int) 'あなたの現在の演算子++()は、プリインクリメント '++ c1'のために動作します。 – Vishal