标题:求高手帮忙! c++ 问题?
取消只看楼主
DreamSkyCC
Rank: 2
来 自:河北赵县
等 级:论坛游民
帖 子:40
专家分:58
注 册:2010-11-28
结帖率:100%
已结贴  问题点数:2 回复次数:0 
求高手帮忙! c++ 问题?
求高手帮忙! c++ 问题?
#include <iostream>
using namespace std;
class Complex
{
    private:
  
        float Real,Image;
    public:
     
        Complex(float r = 0,float i = 0)
        {
            Real = r;
            Image = i;
     
        }
  
        void Show(int i)
        {
            cout<<"c"<< i << "=" << Real << "+" << Image << "i" << endl;
         
        }
        Complex operator+ (Complex &c);
     
        Complex operator- (Complex &c);
     
        void operator= (Complex &c);         

  
};
void Complex::operator= (Complex &c)
{
  
  

    Real = c.Real;
    Image = c.Image;
    return ;  

}
Complex Complex::operator+ (Complex &c)
{
  
    Complex t;
    t.Real = Real + c.Real;
    t.Image = Image + c.Image;
    return t;
}
Complex Complex::operator- (Complex &c)
{
  
    Complex t;
    t.Real = Real - c.Real;
    t.Image = Image - c.Image;
    return t;
}
int main(void)
{
    Complex c1(20,20),c2(30,50),c3;
    c1.Show(1);
    c2.Show(2);
    c3 = c1 + c2;
    c3.Show(3);
     

    return 0;
}
80: error: no match for ‘operator=’ in ‘c3 = (((Complex&)(& c2)))’
chongzai.cpp:36: note: candidates are: void Complex::operator=(Complex&)
搜索更多相关主题的帖子: class Complex private include 
2010-12-08 16:32



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




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

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