代入演算子を使用することで、より効率的なコードにすることができます。
C++ 標準テンプレート・ライブラリーでは、いくつかの標準クラスが定義されています。一部の演算子は、一時オブジェクトを作成し破棄します。この警告メッセージは、必要な一時オブジェクトの数を減らすことで、同じ結果をより効率的に得ることができる別の計算方法を示します。
ID |
問題箇所 |
説明 |
---|---|---|
1 |
呼び出し位置 |
演算子が使用された場所 |
2 |
定義 |
演算子が定義された場所 |
#include <string> #include <iostream> using namespace std; class myClass { public: int i; int j; myClass(int i, int j) { this->i = i; this->j = j; } myClass & operator +=(const myClass &b) { this->i = this->i + b.i; return *this; } myClass operator +(const myClass &b) { *this += b; return *this; } }; int main(int argc, char **argv) { A a(1, 1), b(1, 1); a = a + b; // better is a += b; cout << a.i; return 0; }
© 2010 Intel Corporation. 無断での引用、転載を禁じます。