【发布时间】:2012-03-19 23:03:25
【问题描述】:
在构建和运行时,我的 xcode 中出现重复错误
我有两个文件 file1.m 和 file2.m 都使用相同的变量和函数名
file1.h
#import <UIKit/UIKit.h>
@interface file1 : UIViewController {
IBOutlet UILabel *result;
}
-(IBAction)home;
@end
file1.m
#include<file1.h>
@implementation file1
int count = 0;
int arr[2][2];
file2.h
#import <UIKit/UIKit.h>
@interface file2 : UIViewController {
IBOutlet UILabel *result;
}
-(IBAction)home;
@end
file2.m
#include<file2.h>
@implementation file2
int count = 0;
int arr[2][2];
当构建并运行时,它在 file1.o 和 file2 中给出错误重复符号“count”。 ○ 如果我将他们的名字改为 count1 和 count2,我不会收到任何错误。
在 file1.m 和 file2.m 中,我都在尝试创建全局变量。
有什么方法可以在两个文件中使用相同名称的变量和函数
【问题讨论】:
-
你也可以发布 .h 吗?
-
你在这里定义全局变量吗?如果是这样,你打算这样做吗?请提供更多代码。
-
我发布了一个新代码。 @HermannKlecker 是的,我正在尝试定义全局变量
标签: iphone objective-c xcode