标题:运算符重载时出现问题了
取消只看楼主
zerocn
Rank: 1
等 级:新手上路
帖 子:126
专家分:0
注 册:2006-4-11
 问题点数:0 回复次数:0 
运算符重载时出现问题了
#include <iostream>

using namespace std;

class Complex
{private:
 float r,i;
 public:
 Complex operator + (Complex &b);
 Complex();
 Complex(float &,float &);
 void show();
};

Complex Complex::operator +(Complex &b)
{Complex temp;
 temp.r=r+b.r;
 temp.i=i+b.i;
 return (temp);
 }
 
Complex::Complex()
{r=0;i=0;}
Complex::Complex(float &a, float &b)
{r=a;i=b;}
void Complex::show()
{if(r<0)cout<<r<<"-"<<i<<"i"<<endl;
 else if(r=0)cout<<r<<endl;
 else cout<<r<<"+"<<i<<endl;
               }

int main()
{ Complex c1(10,11),c2(12,13),c3;//编译时这里出错了
  c3=c1+c2;
  c3.show();  
  return 0;
}


这里是报错的消息
no matching function for call to `Complex::Complex(int, int)'
Complex::Complex(float&, float&)
Complex::Complex()


我想是不是创建对象是把"10"看成int形,那么我改为"10F"这样还是不行
搜索更多相关主题的帖子: Complex 运算符 float temp operator 
2008-06-25 17:46



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




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

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