我在全局范围内定义了结构,但是当我尝试使用它时,我得到错误:'co'没有命名为类型,但是当我在功能,一切工作正常不能在全局范围使用结构
typedef struct {
int x;
int y;
char t;
} MyStruct;
MyStruct co;
co.x = 1;
co.y = 2;
co.t = 'a'; //compile error
void f() {
MyStruct co;
co.x = 1;
co.y = 2;
co.t = 'a';
cout << co.x << '\t' << co.y << '\t' << co.t << endl;
} //everything appears to work fine, no compile errors
我做错了什么,或结构只是不能在全球范围内使用?
外'main',你可以拥有的唯一的事情就是声明和函数定义。像'co.x = 1;'这样的分配必须进入'main'(或另一个函数)。 – jogojapan
['cout'可能重复不会命名一个类型](http://stackoverflow.com/questions/9935027/cout-does-not-name-a-type) – jogojapan