这个常在结构体定义的时候出现。
原文链接:http://hi.baidu.com/wwssttt/item/edaa423696b7c5c72e8ec2ae
————————————————————————————————————————————
在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即可。