请教VC编程问题

gy_hlpp 2001-07-06 10:11:33
我的原程序。
#include <math.h>

class TTriangle
{
private:
float a,b,c;
public:
TTriangle(float x=0,float y=0,float z=0)
{
a=x;b=y;c=z;
};
void Set(float &x,float &y,float &z)
{
a=x;b=y;c=z;
};
void Get(float &x,float &y,float &z)
{
x=a;y=b;z=c;
};
friend float Area(TTriangle &);
}

float Area(TTriangle &iT)
{
float tS,tA;
tS=(iT.a+iT.b+iT.c)/2;
tA=sqrt((tS-iT.a)*(tS-iT.b)*(tS-iT.c)*tS));
}

#include <iostream.h>
void main(void)
{
TTriangle iT(3.0,4.0,5.0);
cout<<"the "<<Area(iT);
}


编译错误提示:
-------------------Configuration: 118a - Win32 Debug--------------------
Compiling...
118a.cpp
D:\test\118a.cpp(23) : error C2628: 'TTriangle' followed by 'float' is illegal (did you forget a ';'?)
D:\test\118a.cpp(24) : error C2556: 'class TTriangle __cdecl Area(class TTriangle &)' : overloaded function differs only by return type from 'float __cdecl Area(class TTriangle &)'
D:\test\118a.cpp(20) : see declaration of 'Area'
D:\test\118a.cpp(24) : error C2371: 'Area' : redefinition; different basic types
D:\test\118a.cpp(20) : see declaration of 'Area'
D:\test\118a.cpp(27) : error C2059: syntax error : ')'
D:\test\118a.cpp(27) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Error executing cl.exe.

118a.obj - 4 error(s), 1 warning(s)
谢谢大家。
...全文
149 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gy_hlpp 2001-07-06
  • 打赏
  • 举报
回复
阿丰:兄弟非常非常感谢!!!!!
yxzd 2001-07-06
  • 打赏
  • 举报
回复
1.class的定义后加;
2.sqrt多了一个右括号
3.Area()没有返回值
加上return tA;
azurecrystal 2001-07-06
  • 打赏
  • 举报
回复
首先,如果你是在一个文件中实现这些的话,请把#include <iostream.h>放到文件的顶行。
其次,set()函数和get()函数的形参类型应为浮点,而不是引用。
再试试。
ahphone 2001-07-06
  • 打赏
  • 举报
回复
1.class的定义后加;
2.sqrt多了一个右括号
ahphone 2001-07-06
  • 打赏
  • 举报
回复
#include <math.h>
#include <iostream.h>

class TTriangle
{
private:
float a,b,c;
public:
TTriangle(float x=0,float y=0,float z=0)
{
a=x;b=y;c=z;
};
void Set(float &x,float &y,float &z)
{
a=x;b=y;c=z;
};
void Get(float &x,float &y,float &z)
{
x=a;y=b;z=c;
};
friend float Area(TTriangle &iT);
};

float Area(TTriangle &iT)
{
float tS,tA;
tS=(iT.a+iT.b+iT.c)/2;
tA=sqrt( (tS-iT.a) * (tS-iT.b) * (tS-iT.c) * tS );
}


void main(void)
{
TTriangle iT(3.0,4.0,5.0);
cout<<"the "<<Area(iT);
}

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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