标题:请问隐式转换的问题
取消只看楼主
ysmashiamaro
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-8-21
 问题点数:0 回复次数:0 
请问隐式转换的问题

我的源文件如下:

#include <iostream.h>

class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r){real=r;imag=0;}
Complex(double r,double i){real=r;imag=i;}
Complex operator + (Complex c2);/*改为Complex operator + (Complex &c2)就出现编译错误*/
void display();
private:
double real;
double imag;
};

Complex Complex::operator + (Complex c2)/*也改为Complex operator + (Complex &c2)*/
{return Complex(real+c2.real,imag+c2.imag);}
void Complex::display()
{cout<<"("<<real<<","<<imag<<"i)"<<endl;}
int main()
{
Complex c1(3,4),c2(5,-10),c3;
c3=c1+2.5;
c3.display();
return 0;
}

我不明白为什么会这样,我用的是VC6.0编译器,有哪位高人帮我解答一下,万分感谢。

搜索更多相关主题的帖子: double Complex private display 
2007-08-21 20:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-164421-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.135353 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved