帮我看看程序为什么通不过???

zhaodong 2002-12-14 03:20:12
////example of complex class and convertion of class type
//authro:zhaodong
/*
#include <iostream.h>
#include <math.h>
#define pi 3.1415
class Complex;

class TTT
{

public:
double r;
double q;
public:
TTT(double t1=0,double t2=0 )
{
r = t1;
q = t2;
}

operator Complex()
{
Complex *temp;
temp->Rem = r*cos(q);
temp->Imp = r*sin(q);
return *temp;
}

};

class Complex
{
public:
double Rem;
double Imp;
public:
Complex()
{
Rem = 0;
Imp = 0;
}

Complex(int a)
{
Rem = a;
Imp = 0;
}
Complex(int a, int b)
{
Rem = a;
Imp = b;
}
friend Complex operator+(Complex t1, Complex t2)
{
Complex temp;
temp.Rem = t1.Rem + t2.Rem;
temp.Imp = t1.Imp + t2.Imp;
return temp;
}
friend Complex operator-(Complex t1, Complex t2)
{
Complex temp;
temp.Rem = t1.Rem - t2.Rem;
temp.Imp = t1.Imp - t2.Imp;
return temp;
}
friend Complex operator*(Complex t1, Complex t2)
{
Complex temp;
temp.Rem = t1.Rem*t2.Rem - t1.Imp*t2.Imp;
temp.Imp = t1.Rem*t2.Imp + t1.Imp*t2.Rem;
return temp;
}
friend Complex operator/(Complex t1, Complex t2)
{
Complex temp;
temp.Rem = (t1.Rem*t2.Rem + t1.Imp*t2.Imp)/(t2.Imp*t2.Imp + t2.Rem*t2.Rem);
temp.Imp = (t1.Imp*t2.Rem - t1.Rem*t2.Imp)/(t2.Imp*t2.Imp + t2.Rem*t2.Rem);
return temp;
}
//*
operator TTT()
{
TTT temp;
temp.r = sqrt(Rem*Rem + Imp*Imp);
if ((Rem == 0 )&&(Imp > 0 ))
{
temp.q = pi/2;
}
else if ((Rem == 0)&&(Imp < 0))
{
temp.q = (3*pi)/2;
}
else
{
temp.q = atan(Imp/Rem);
}
return temp;
}

};
编译环境为vc6.0,两个类有互相使用的关系,为什么有错呢??请高手指点
...全文
16 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
widewave 2002-12-14
  • 打赏
  • 举报
回复
operator Complex()
{
Complex *temp; // temp没有指向有效内存
temp->Rem = r*cos(q);
temp->Imp = r*sin(q);
return *temp;
}
rabies 2002-12-14
  • 打赏
  • 举报
回复
operator Complex()
{
Complex *temp;
temp->Rem = r*cos(q);
temp->Imp = r*sin(q);
return *temp;
}
前面虽然有声明,但是这样用一定要有类的定义才可以

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧