I defined struct in the global scope, but when I try to use it, I get error: ‘co’ does not name a type, but when I do the same in a function, everything works fine
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 << '' << co.y << '' << co.t << endl;
} //everything appears to work fine, no compile errors
Am I doing something wrong, or structures just cannot be used in global scope?
See Question&Answers more detail:os