| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 479 人关注过本帖
标题:程序找不到错?
只看楼主 加入收藏
yanyananlin
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-10-21
收藏
 问题点数:0 回复次数:3 
程序找不到错?

#ifndef Complex_H
#define Complex_H
#include <iostream>
using namespace std;
class Complex
{ public: Complex(double a =0,double b=0);
SetComplex(double,double);
PrintComplex();
operator + (const Complex &)
private: double realpart;
double imaginarypart;

};
#endif
#include <iostream>
using namespace std;
#include "Complex.h"
Complex::Complex(double a,double b){SetComplex(a,b);}
Complex::SetComplex(double a,double b){realpart=a,imaginarypart=b;}
Complex::operator +(const Complex & a)
{ Complex d;
d.realpart=realpart+a.realpart;
d.imaginarypart=imaginarypart+a.imaginarypart;
return d;
}
Complex::PrintComplex(){cout<<realpart<<"+"<<imaginarypart<<"i"<<endl;}
double main ()
{ Complex a(1,2);
Complex b(3,5);
Complex c;
a.PrintComplex();
b.PrintComplex();
c.PrintComplex();
return 0;
}
-------------------Configuration: complex - Win32 Debug--------------------
Compiling...
complex.cpp
E:\Program Files\MSDEV98\MY PROJECT\安林\complex\complex.cpp(9) : error C2440: 'return' : cannot convert from 'class Complex' to 'int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\Program Files\MSDEV98\MY PROJECT\安林\complex\complex.cpp(18) : error C2039: 'Add' : is not a member of 'Complex'
e:\program files\msdev98\my project\安林\complex\complex.h(6) : see declaration of 'Complex'
执行 cl.exe 时出错.

complex.exe - 1 error(s), 0 warning(s)



找了半天没找到~大家帮我找找错好吗?谢谢了~

[此贴子已经被作者于2007-11-17 21:19:03编辑过]

搜索更多相关主题的帖子: Complex private include public 
2007-11-17 20:58
zhb_ice
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2007-10-6
收藏
得分:0 
operator + (const Complex &)
后面没有加 ;

重装加法运算应该有返回值
改成 Complex& operator + (const Complex &);
下面的实习部分也改一下

2007-11-17 21:57
a217zxg
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-10-20
收藏
得分:0 

这样是没有错的!
#ifndef Complex_H
#define Complex_H
#include <iostream>
using namespace std;
class Complex
{
public: Complex(double a =0,double b=0);
SetComplex(double,double);
PrintComplex();
Complex operator+(const Complex &);
private: double realpart;
double imaginarypart;

};
#endif
#include <iostream>
using namespace std;
//#include"Complex.h"
Complex::Complex(double a,double b){SetComplex(a,b);}
Complex::SetComplex(double a,double b){realpart=a,imaginarypart=b;}
Complex Complex::operator +(const Complex & a)
{
Complex d;
d.realpart=realpart+a.realpart;
d.imaginarypart=imaginarypart+a.imaginarypart;
return d;
}
Complex::PrintComplex(){cout<<realpart<<"+"<<imaginarypart<<"i"<<endl;}
void main ()
{ Complex a(1,2);
Complex b(3,5);
Complex c;
a.PrintComplex();
b.PrintComplex();
c.PrintComplex();
}

2007-11-17 22:19
yanyananlin
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-10-21
收藏
得分:0 

哦,明白了,谢谢你们!

2007-11-19 16:23
快速回复:程序找不到错?
数据加载中...
 
   



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

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