65,211
社区成员
发帖
与我相关
我的任务
分享
请大家帮我看一下这个错误的原因,如何解决:
// MyApp.cpp
...
CMyApp theApp;
// 在此处定义全局变量
struct C
{
int x;
int y;
};
C c;
c.x =0;
error C2143: syntax error : missing ';' before '.' // 说的是 c.x =0; 这一行
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
struct C
{
int x;
int y;
};
void main()
{
C a;//若源文件为.c文件,则次写法错误,须写成struct C a;
//若源文件为.cpp文件,则可编译成功
a.x =0;
}
extern struct C
{
int x;
int y;
} c;
//而不是:
extern C c;
typedef struct
{
int x;
int y;
}C;
C c;
c.x =0;
typedef struct
{
int x;
int y;
}C;
C c;
c.x =0;