| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 903 人关注过本帖
标题:复数相加问题解决不了
取消只看楼主 加入收藏
cwl168
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2012-12-14
结帖率:8.33%
收藏
 问题点数:0 回复次数:0 
复数相加问题解决不了
#include<iostream.h>

class Complex
{
private:
    float real,imag;
public:
    Complex(){ real=0;imag=0;}
    Complex(float a,float b):real(a),imag(b){}
    Complex operator+(Complex &c);
    Complex operator +(int &i);
    friend ostream& operator<<(ostream &,Complex &);
    friend Complex operator +(Complex &,int &);
    void display();

};
Complex Complex::operator+(Complex &c)
{
    return Complex(real+c.real,imag+c.imag);
}

void Complex::display()
{

    cout<<real<<"+"<<imag<<"i"<<endl;
}
ostream &operator<<(ostream &ouput,Complex &c)
{
     ouput<<c.real<<"+"<<c.imag<<"i"<<endl;
     return ouput;
}
Complex Complex::operator +(int &i)
{     
    return Complex(real+i,imag);
}
Complex operator+(Complex &c,int &i)
{
     return Complex(c.real+i,c.imag);
}
int main()
{
    Complex c1(1,2),c2(2,3),c3,c4;
    //c3=c1+c2;
   
    c4=c2+4;
    cout<<c4;
    return 0;
}

--------------------Configuration: 10_3 - Win32 Debug--------------------
Compiling...
10_3.cpp
F:\Study Garden\上机内容\c++\10_3\10_3.cpp(45) : error C2679: binary '+' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)
执行 cl.exe 时出错.

10_3.obj - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: include display void private Complex 
2013-01-11 16:54
快速回复:复数相加问题解决不了
数据加载中...
 
   



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

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