2011-04-05 170 views
1

编译时以下错误的含义是什么?C编译错误

Tilemap.h:21: error: conflicting types for ‘ThreeDWorld’ 
Tilemap.h:21: error: previous declaration of ‘ThreeDWorld’ was here 
Tilemap.h:29: error: conflicting types for ‘CGPoint’ 
Tilemap.h:29: error: previous declaration of ‘CGPoint’ was here 
Tilemap.h:31: error: conflicting types for ‘tileForCoordinates’ 
Tilemap.h:31: error: previous declaration of ‘tileForCoordinates’ was here 

为什么它给了什么呢?我的源文件有它的一个实例是这样

typedef struct 
{ 
int xPosition; 
int yPosition; 
} 
CGPoint; 
+0

你是否偶然使用Obj-C和XCODE? – 2011-04-05 16:38:38

+0

Textmate和Terminal – jarryd 2011-04-05 16:48:14

回答

5

你是否包括来自多个地方的头文件中的错误?如果是的话,在头文件中使用警卫。

例如,在Tilemap.h:

#ifndef TILEMAP_H 
#define TILEMAP_H 

// header file contents 

#endif /* TILEMAP_H */ 
+1

一些编译器支持#pragma一次。 – flolo 2011-04-05 16:33:33

+0

很酷。感谢这一点。 ;) – jarryd 2011-04-05 16:36:19

2

沾些包容守卫你的头。

您的类型定义在您的编译单元中出现多次。

2

您包含头文件两次。

在我自己的代码,我包的所有头文件与

#ifndef HEADER_FILE_NAME 
#define HEADER_FILE_NAME 

#endif 

,以避免此类错误。