redefinition of formal parameter 'a'什么意思啊,我是初学者,麻烦了

#include<iostream.h>
#include<math.h>
class Cpoint
{
public:
double x,y;
Cpoint(double a,double b)
{x=a;y=b;}
};
class tria
{
public:
friend double length(Cpoint &p1,Cpoint &p2,Cpoint &p3,tria &a);
double area()
{
double t=(l1+l2+l3)/2;
return sqrt(t*(t-l1)*(t-l2)*(t-l3));
}
double l1,l2,l3;
};
double length(Cpoint &p1,Cpoint &p2,Cpoint &p3,tria &a)
{
double a=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
double b=sqrt((p2.x-p3.x)*(p2.x-p3.x)+(p2.y-p3.y)*(p2.y-p3.y));
double c=sqrt((p3.x-p1.x)*(p3.x-p1.x)+(p3.y-p1.y)*(p3.y-p1.y));
l1=a;l2=b;l3=c;
}
void main()
{
Cpoint p1(1.5,5.0),p2(3.4,5.1),p3(4.7,8.1);
tria a;
length(p1,p2,p3,a);
cout<<a.area<<endl;
}
错误如下
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(23) : error C2082: redefinition of formal parameter 'a'
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(26) : error C2065: 'l1' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(26) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class tria' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(26) : error C2065: 'l2' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(26) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(26) : error C2065: 'l3' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(26) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
C:\Program Files\Microsoft Visual Studio\MyProjects\lab\06251103142.cpp(33) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
执行 cl.exe 时出错.

06251103142.obj - 1 error(s), 0 warning(s)
我是新人,没什么分,真的麻烦了

redefinition of formal parameter 'a'的意思是形式参数重新定义a,在同一个函数内不能定义两次同一个变量。

比如zhiint ss(int a)

{

int a; //这里的a 编译的时候就会提示daoredefinition of formal parameter 'a'

}

双击第一个错误 看下错误指针指向哪一行 ,说明那里的a是重新定义的,也就是前面定义了一个a。

扩展资料:

C语言函数的参数分为两种,分别是形式参数与实际参数。

①形式参数:

在定义函数时函数名后面括号中的变量名称称为形式参数(简称形参),即形参出现在函数定义中。形参变量只有在被调用时才会为其分配内训单元,在调用结束时,即刻释放所分配的内存单元。

因此,形参只在函数内部有效,只有当函数被调用时,系统才为形参分配存储单元,并完成实参与形参的数据传递。在函数未被调用时,函数的形参并不占用实际的存储单元,也没有实际值。

②实际参数:

主调函数中调用一个函数时,函数名后面括号中的参数称为实际参数(简称实参),即实参出现在主调函数中。

实参可以是常量,变量,表达式,函数等,无论实参是何种类型的量,在进行函数调用时,它们都必须具有确定的值,以便把这些值传递给形参。因此应预先用赋值,输入等办法使实参获得确定值。

说明:在被定义的函数中,必须指定形参的类型。实参与形参的类型应相同或赋值兼容。实参和形参在数量上,类型上,顺序上应该严格一致,否则会发生类型不匹配的错误。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-26
形式参数 重新定义,在同一个函数内不能定义两次同一个变量
比如int ss(int a)
{

int a; //这里的a 编译的时候就会提示redefinition of formal parameter 'a'
}

双击第一个错误 看下错误指针指向哪一行 ,说明那里的a是重新定义的,也就是前面定义了一个a
我也是新手!!不过希望可以帮到你本回答被网友采纳
第2个回答  2018-06-29
int ss(int a)这句括号中定义了a,函数ss里再定义int a就重复了。我学c语言的时候遇到了,来搜一下发现这么简单。
相似回答