以下代碼無法使用-std=c++0x
開關在g ++版本4.5.0中進行編譯。我收到以下錯誤信息:C++在g ++中爲std :: complex 11複製分配4.5 - 與'operator +'不匹配
error: no match for 'operator+' in 'std::pow [with _Tp = float, _Up = int, typename __gnu_cxx::__promote_2<_Tp, _Up>::__type = double](((const std::complex<float>&)((const std::complex<float>*)(& x))), ((const int&)((const int*)(&2)))) + y'
我相信這涉及到可分配要求提到here。我是否應該爲複雜的定義自己的複製賦值運算符?如果是這樣,怎麼樣?
#include <complex>
using namespace std;
int main(int argc, char *argv[]) {
complex<float> x,y;
x = pow(x,2); // ok
x = x + y; // ok
x = pow(x,2) + y; // error
return 0;
}
錯誤,簡化,說:「沒有運營商+需要一個複雜的和複雜的」 –
Cubbi
@parapura rajkumar:不幸的是它不。 – user2023370
這在VS2010編譯可能需要模板或typename關鍵字。 – AJG85