资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
#include #include using namespace std; class complex public: complex(double r=0.0,double i=0.0);/在声明构造函数时指定默认参数值 double abscomplex(); private: double real; double imag; ; complex:complex(double r,double i)/定义构造函数 real=r; imag=i; double complex:abscomplex() double t; t=real*real+imag*imag; return sqrt(t); int main() complex s1;/不传递参数 complex s2(1.1);/仅传递一个参数 complex s3(1.1,2.2);/传递两个参数 cout #include using namespace std; class complex public: complex();/默认构造函数 complex(double r=0.0,double i=0.0);/在声明构造函数时指定默认参数值,亦属于默认构造函数 double abscomplex(); private: double real; double imag; ; Complex:complex(double r,double i) real=r; imag=i; double complex:abscomplex() double t; t=real*real+imag*imag; return sqrt(t); int main() complex s1;/系统无法识别,产生二义性 complex s2(1.1);/系统无法识别,产生二义性 complex s3(1.1,2.2); couts1.abscomplex()endl; couts2.abscomplex()endl; couts3.abscomplex()endl; return 0; 一个类只能 有一个默认 构造函数warning C4520: complex : multiple default constructors specified默认构造 函数指定多个 C:Program FilesMicrosoft Visual StudioMyProjectsg16.cpp(21) : error C2668: complex:complex : ambiguous call to overloaded function 执行 cl.exe 时出错.16.obj - 1 error(s), 0 warning(s)错误提示
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号