| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 940 人关注过本帖
标题:error: no matching function for call to 'Complex::Complex()'|
取消只看楼主 加入收藏
床至只局
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2015-2-1
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:1 
error: no matching function for call to 'Complex::Complex()'|
#include<iostream>
using namespace std;

class Complex
{
private:
    int real,imag;
protected:
public:
    Complex(int r,int i);
    ~Complex();
    void show();
    friend ostream &operator<<(ostream &os,const Complex &f);
    friend istream &operator>>(istream &is,Complex &f);
    Complex operator+(Complex &obj2);
    Complex operator-(Complex &obj2);
    Complex operator*(Complex &obj2);
};
Complex Complex::operator+(Complex &obj2)
{
    Complex temp;//这里有错???????????????????????????????????????????????
    temp.real=this->real+obj2.real;
    temp.imag=this->imag+obj2.imag;
    return temp;
}
Complex Complex::operator-(Complex &obj2)
{
    this->real-=obj2.real;
    this->imag-=obj2.imag;
    return *this;
}
Complex Complex::operator*(Complex &obj2)
{
    this->real*=obj2.real;
    this->imag*=obj2.imag;
    return *this;
}
Complex::Complex(int r=0,int i=0):real(r),imag(i)
{
    cout<<real<<"+"<<imag<<"i"<<endl;
    cout<<"storage space allocation."<<endl;
}
Complex::~Complex()
{
    cout<<"delete space finished!"<<endl;
}
void Complex::show()
{
    cout<<real<<"+"<<imag<<"i"<<endl;
}
ostream &operator<<(ostream &os,const Complex &f)
{
    os<<f.real<<"+"<<f.imag<<"i"<<endl;
}
istream &operator>>(istream &is,Complex &f)
{
    is>>f.real>>f.imag;
    return is;
}

int main()
{
    Complex obj,obj2;
    cin>>obj>>obj2;
    cout<<obj<<obj2;
    cout<<obj+obj2<<endl<<obj-obj2<<endl<<obj*obj2;
    return 0;
}
搜索更多相关主题的帖子: function matching Complex private include 
2015-04-26 21:50
床至只局
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2015-2-1
收藏
得分:0 
回复 2楼 yangfrancis
谢谢你,按照你的建议我重新修改了一下,程序顺利运行了
2015-04-26 22:59
快速回复:error: no matching function for call to 'Complex::Complex()'|
数据加载中...
 
   



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

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