找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1562|回复: 0

运算符重载错误

[复制链接]
发表于 2009-11-4 00:27:36 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include<math.h>
#include"string.h"
#include "stdafx.h"
class CComplex
{
public:
CComplex();
CComplex(double dblx,double dbly);
CComplex(const CComplex&other);
virtual ~CComplex(){};
void Setreal(double dblx);
void Setimag(double dbly);
double Getreal();
double Getimag();
CString ToString() const;
void FromString(CString s,const CString& sDelim=" ");
bool operator==(const CComplex &cpxx) const;
bool operator!=(const CComplex &cpxx) const;
CComplex& operator=(const CComplex &cpxx);
CComplex operator+(const CComplex &cpxx) const;
CComplex operator-(const CComplex &cpxx) const;
CComplex operator*(const CComplex &cpxx) const;
CComplex operator/(const CComplex &cpxx) const;
double Abs() const;
void Root(int n,CComplex cpxr[]) const;
CComplex Pow(double dblw) const;
CComplex Pow(CComplex cpxw,int n=0) const;
CComplex Log() const;
CComplex Sin() const;
CComplex Cos() const;
CComplex Tan() const;
protected:
double m_dblx;
double m_dbly;
};
CComplex::CComplex()
{
m_dblx=0.0;
m_dbly=0.0;
}
CComplex::CComplex(double dblx,double dbly)
{
m_dblx=dblx;
m_dbly=dbly;
}
CComplex::CComplex(const CComplex &other)
{
m_dblx=other.m_dblx;
m_dbly=other.m_dbly;
}
void CComplex::Setreal(double dblx)
{
m_dblx=dblx;
}
void CComplex::Setimag(double dbly)
{
m_dbly=dbly;
}
double CComplex::Getreal()
{
return m_dblx;
}
double CComplex::Getimag()
{
return m_dbly;
}
CString CComplex::ToString() const
{
CString s;
if(m_dblx!=0.0)
{
if(m_dbly>0)
s.Format("%f+%fj",m_dblx,m_dbly);
else if(m_dbly<0)
s.Format("%f-%fj",m_dblx,fabs(m_dbly));
else
s.Format("%f",m_dblx);
}
else
{
if(m_dbly>0)
s.Format("%f",m_dbly);
else if(m_dbly<0)
s.Format("-%fj",fabs(m_dbly));
else
s.Format("%f",m_dblx);
}
return s;
}
void CComplex::FromString(CString s,const CString &sDelim)
{
int npos=s.Find(sDelim);
if(npos==-1)
{
s.TrimLeft();
s.TrimRight();
m_dblx=atof(s);
m_dbly=0;
}
else
{
int nlen=s.GetLength();
CString sleft=s.Left(npos);
CString sright=s.Right(nlen-npos-1);
sleft.TrimLeft();
sright.TrimRight();
m_dblx=atof(sleft);
m_dbly=atof(sright);
}
}

bool CComplex::operator ==(const CComplex & cpxx) const
{
return (m_dblx==cpxx.m_dblx&&m_dbly==cpxx.m_dbly);
}

bool CComplex::operator !=(const CComplex & cpxx) const
{
return (m_dblx!=cpxx.m_dblx || m_dbly!=cpxx.m_dbly);
}
CComplex& CComplex::operator =(const CComplex & cpxx)
{
m_dblx=cpxx.m_dblx;
m_dbly=cpxx.m_dbly;
return *this;
}
CComplex CComplex::operator +(const CComplex& cpxx) const
{
double x=m_dblx+cpxx.m_dblx;
double y=m_dbly+cpxx.m_dbly;

return CComplex(x,y);
}
CComplex CComplex::operator -(const CComplex & cpxx) const
{
double x=m_dblx-cpxx.m_dblx;
double y=m_dbly-cpxx.m_dbly;
return CComplex(x,y);
}
CComplex CComplex::operator *(const CComplex& cpxx) const
{
double x=m_dblx*cpxx.m_dblx-m_dbly*cpxx.m_dbly;
double y=m_dblx*cpxx.m_dbly-m_dbly*cpxx.m_dblx;
return CComplex(x,y);
}
double CComplex::Abs() const
{
double x=fabs(m_dblx);
double y=fabs(m_dbly);
if(m_dblx==0)
return y;
if(m_dbly==0)
return x;
if (x>y)
return (x*sqrt(1+(y/x)*(y/x)));
return (y*sqrt(1+(y/x)*(y/x)));
}


void CComplexCaculatorDlg::OnPlus()
{
// TODO: Add your control notification handler code here
UpdateData();
CComplex cpxA(double m_dblA,double m_dblB);
CComplex cpxB(double m_dblC,double m_dblD);
CComplex cpxC= cpxA*cpxB;
m_strResult=cpxC.ToString();
UpdateData(FALSE);
}
--------------------Configuration: ComplexCaculator - Win32 Debug--------------------
Compiling...
ComplexCaculatorDlg.cpp
D:\c++\CComplex\ComplexCaculatorDlg.cpp(199) : error C2296: '*' : illegal, left operand has type 'class CComplex (__cdecl *)(double,double)'
D:\c++\CComplex\ComplexCaculatorDlg.cpp(199) : error C2297: '*' : illegal, right operand has type 'class CComplex (__cdecl *)(double,double)'
D:\c++\CComplex\ComplexCaculatorDlg.cpp(242) : error C2228: left of '.Abs' must have class/struct/union type
Error executing cl.exe.
Creating browse info file...
ComplexCaculator.exe - 3 error(s), 0 warning(s)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 21:34 , Processed in 0.239991 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表