NevzatR
NevzatR

Reputation: 245

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 whats the problem???

Upvotes: 1

Views: 297

Answers (2)

GoldWater
GoldWater

Reputation: 91

I meet the question. As Says , because the variable x is shared among classes. Modify the variable x to another name.

Upvotes: 0

SmallChess
SmallChess

Reputation: 8116

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.

Upvotes: 2

Related Questions