#报错内容是[Error] expected primary-expression before 'A'
#我的代码是
#include <stdio.h>
typedef struct{
float r;
float i;
}complex;
int main(){
void create(complex& A,complex& B,float m,float n,float p,float q);
int x=5;int y=6;//第一个复数的实部与虚部
int a=2;int b=3;//第二个复数的实部与虚部
create(complex A,complex B,x,y,a,b)
}
void create(complex& A,complex& B,float m,float n,float p,float q){
A.r=m;
A.i=n;// 第一个复数的实部与虚部 已经创建完成
B.r=p;
B.i=q;
printf("%d %d %d %d",A.i,A.i,B.r,B.i);
}
create(complex A,complex B,x,y,a,b)
改为
complex A,B;
create(A,B,x,y,a,b);
你这个写法很混乱。调用函数不需要指定参数类型,直接传递变量就行。但得先定义变量
complex前面需要加上struct。如下:
void create(struct complex& A,struct complex& B,float m,float n,float p,float q)
还有第10行的create函数中,A和B前面不需要再加complex,最后加上分号
int main(){
void create(struct complex& A,struct complex& B,float m,float n,float p,float q);
struct complex A,B;
int x=5;int y=6;//第一个复数的实部与虚部
int a=2;int b=3;//第二个复数的实部与虚部
create( A, B,x,y,a,b);
return 0;
}
为struct起名的时候写为
typedef struct complex{
float r;
float i;
};
即可将其作为别名使用