ld: duplicate symbol _x in /users/.... ERROR
I have 2 different classes but same primitive type declaration as you see below
int x = 0;
- (void)viewDidLoad{
[super viewDidLoad];
}
if I change one of them name "x" to "y" there is no error? WHY? seperate classes same variable开发者_JS百科 whats the problem???
That's because the variable x is shared among classes. I think (but never tried) if you declare extern int x in another file, you could share the x variable.
Try static int x = 0. In general, always declare an internal class variable as static unless you want to share it with another file.
I meet the question. As Says , because the variable x is shared among classes. Modify the variable x to another name.
精彩评论