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; }
解决方法
Function template pow shall have additional overloads sufficient to
ensure,for a call with at least one argument of typecomplex<T>
:
If either argument has type
complex<long double>
or typelong double
,then both arguments are effectively cast tocomplex<long
.
double>Otherwise,if either argument has type
complex<double>
,double
,or an integer type,then both arguments are effectively cast to
complex<double>
.Otherwise,if either argument has type
complex<float>
orfloat
,then both arguments are effectively cast tocomplex<float>
.
2被提升为double,而pow(complex< float>,double)返回复数< double>.
原文地址:https://www.jb51.cc/c/111334.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。