| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 680 人关注过本帖
标题:错误提示,不明白。
只看楼主 加入收藏
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
结帖率:71.43%
收藏
已结贴  问题点数:10 回复次数:4 
错误提示,不明白。
# include<iostream>
using namespace std;

class Complex{
double real,imag;
public:
    Complex(double r=0,double i=0):real(r),iamg(i){}
    double Real(){
        return Complex::real;
    }
    double Imag(){
        return Complex::imag;
    }
    Complex operator +(Complex &c);
    Complex operator +(double d);
    Complex operator =(Complex c);
};

Complex Complex::operator +(Complex &c){
    Complex temp;
    temp.real=real+c.real;
    temp.imag=image+c.imag;
    return temp;
}
Complex Complex::operator +(double d){
    Complex temp;
    temp.real=real+d;
    temp.imag=imag;
    return temp;
}
Complex Complex::operator =(Complex c){
    real=c.real;
    iamg=c.imag;
    return *this;
}

void main(){
    Complex c1(3,4),c2(5,6),c3(0,0);
   
    cout<<"c1 = "<<c1.Real()<<" + j"<<c1.Imag()<<endl;
    cout<<"c2 = "<<c2.Real()<<" + j"<<c2.Imag()<<endl;
    c3=c1+c2;
    cout<<"c3 = "<<c3.Real()<<" + j"<<c3.Imag()<<endl;
    cout<<"c3+6.5 = "<<c3.Real()<<"  + j"<<c3.Imag()<<endl

}
编译后:
--------------------Configuration: OperateCoverObject - Win32 Debug--------------------
Compiling...
PluralClass.cpp
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(7) : error C2614: 'Complex' : illegal member initialization: 'iamg' is not a base or member
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(22) : error C2065: 'image' : undeclared identifier
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(33) : error C2065: 'iamg' : undeclared identifier
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(46) : error C2143: syntax error : missing ';' before '}'
执行 cl.exe 时出错.

OperateCoverObject.exe - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: 提示 
2009-11-07 16:47
cookies5000
Rank: 2
等 级:论坛游民
帖 子:33
专家分:48
注 册:2009-10-25
收藏
得分:5 
构造函数成员列表:
Complex(double r=0,double i=0):real(r),iamg(i){}

应为:imag(i)
2009-11-07 17:48
cookies5000
Rank: 2
等 级:论坛游民
帖 子:33
专家分:48
注 册:2009-10-25
收藏
得分:5 
改了几处:
///////////////////////////////

# include<iostream>
using namespace std;

class Complex{
double real,imag;
public:
    Complex(double r=0,double i=0):real(r),imag(i){}
    double Real(){
        return Complex::real;
    }
    double Imag(){
        return Complex::imag;
    }
    Complex operator +(Complex &c);
    Complex operator +(double d);
    Complex operator =(Complex c);
};

Complex Complex::operator +(Complex &c){
    Complex temp;
    temp.real=real+c.real;
    temp.imag=imag+c.imag;
    return temp;
}
Complex Complex::operator +(double d){
    Complex temp;
    temp.real=real+d;
    temp.imag=imag;
    return temp;
}
Complex Complex::operator =(Complex c){
    real=c.real;
    imag=c.imag;
    return *this;
}

void main(){
    Complex c1(3,4),c2(5,6),c3(0,0);
   
    cout<<"c1 = "<<c1.Real()<<" + j"<<c1.Imag()<<endl;
    cout<<"c2 = "<<c2.Real()<<" + j"<<c2.Imag()<<endl;
    c3=c1+c2;
    cout<<"c3 = "<<c3.Real()<<" + j"<<c3.Imag()<<endl;
    cout<<"c3+6.5 = "<<c3.Real()<<"  + j"<<c3.Imag()<<endl;

}
2009-11-07 17:54
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
收藏
得分:0 
回复 2楼 cookies5000
谢谢你的帮助!!

只有仇恨才是永恒的
2009-11-07 21:54
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
收藏
得分:0 
回复 3楼 cookies5000
谢谢你的帮助!!!

只有仇恨才是永恒的
2009-11-07 21:55
快速回复:错误提示,不明白。
数据加载中...
 
   



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

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