编译错误:expected specifier-qualifier-list before

转载于:http://www.cnblogs.com/lu-yang/archive/2011/11/24/2261282.html

在oc中经常会遇到expected specifier-qualifier-list before sth之类得编译错误,造成这种错误得主要原因就是使用了未被定义的变量。关于specifier-qualifier-list的定义:It's a list of specifiers and qualifiers :-) Specifiers are things like void, char, struct Foo, etc., and qualifiers are keywords like const and volatile. See this C grammar for the definition.如:

typedef struct {
char *key;
long canTag;
long canSet;
long allowMultiple;
confType *next;
} confType;

由于confType未被完全定义即在定义中使用,这样就会报错,常规得解决办法有:

1.

typedef struct confType {
char *key;
long canTag;
long canSet;
long allowMultiple;
struct confType*next;
} confType;


2.
typedef structconfType confType;

struct confType {
char *key;
long canTag;
long canSet;
long allowMultiple;
confType *next;
};


上述例子可参考
http://stackoverflow.com/questions/2894639/what-is-a-specifier-qualifier-list
http://stackoverflow.com/questions/3888569/expected-specifier-qualifier-list-before
在实际实验过程中会发现还会有一种方法可以解决此问题:
假如有一个ParserDemo工程,而其中有ParserDemoAppDelegate.h/ParserDemoAppDelegate.m和ParserDemoViewController.h/ParserDemoViewController.m. 有时候为了使用C++代码,经常会将后者改为.mm但忘记将前者修改,这样也会报类似的错误,解决办法很简单,就是将二者都改成.mm即可。

你可能感兴趣的:(问题及解决办法)