概述
一口气看到了第四章,自以为C学过,所以关于表达式,赋值语句部分 能跳的就跳过了.可是在4.6复数操作符部分还是出现了问题:关于复数+= -= 操作符 的重载,在linux下编译总是出错!
#include<vector>
#include<iostream>
#include<complex>
using namespace std;
inline complex<double> & operator -=(complex<double> &cval, double dval)
{
return cval -= complex<double> (dval);
}
inline complex<double> & operator *=(complex<double> &cval, double dval)
{
return cval *= complex<double> (dval);
}
inline complex<double> & operator /=(complex<double> &cval, double dval)
{
return cval /= complex<double> (dval);
}
main()
{
complex<double> cval(2.5,2.6);
double dval = 2.0 ;
cval -= 1;
cout<<cval<<endl;
cval *= 1;
cout<<cval<<endl;
cval /= 1;
cout<<cval<<endl;
}
出错提示!
g++ bug.cpp
bug.cpp: In function ‘int main()’:
bug.cpp:23: error: ambiguous overload for ‘operator-=’ in ‘cval -= 1’
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/complex:1235: note: candidates are: std::complex<double>& std::complex<double>::operator-=(double)
bug.cpp:7: note: std::complex<double>& operator-=(std::complex<double>&, double)
bug.cpp:25: error: ambiguous overload for ‘operator*=’ in ‘cval *= 1’
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/complex:1242: note: candidates are: std::complex<double>& std::complex<double>::operator*=(double)
bug.cpp:11: note: std::complex<double>& operator*=(std::complex<double>&, double)
bug.cpp:27: error: ambiguous overload for ‘operator/=’ in ‘cval /= 1’
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/complex:1249: note: candidates are: std::complex<double>& std::complex<double>::operator/=(double)
bug.cpp:15: note: std::complex<double>& operator/=(std::complex<double>&, double)
这个问题先提出来 以后解决
最后
以上就是动听小蝴蝶为你收集整理的 学习C++ Primer 笔记 3的全部内容,希望文章能够帮你解决 学习C++ Primer 笔记 3所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复