C++ 这个错误是什么意思:“错误:'type_name'之前的预期说明符限定符列表”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/608175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:13:06  来源:igfitidea点击:

What does this error mean: "error: expected specifier-qualifier-list before 'type_name'"?

c++cpointersstruct

提问by Paul Wicks

I've been working on the Cell processor and I'm trying to create a struct that will hold an spe_context_ptr_t, which will be used within the thread to launch an spe context and will also hold a pointer to something else that will be passed to the spu context from within the thread (currently I'm trying to just make it a generic pointer, but in actuality it will be a pointer to another structure I've defined). When I try and compile, I get the following error:

我一直在研究 Cell 处理器,我正在尝试创建一个包含 的结构体,它将spe_context_ptr_t在线程中使用以启动 spe 上下文,并且还将包含一个指向将传递给spu 上下文中的线程(目前我试图让它成为一个通用指针,但实际上它将是一个指向我定义的另一个结构的指针)。当我尝试编译时,出现以下错误:

spu/../common.h:38: error: expected specifier-qualifier-list before 'spe_context_ptr_t'

// here is the offending line(s)

typedef struct _PTHREAD_BLOCK {
    spe_context_ptr_t * context; // Error happens here
    uintptr32_t  args; 
 } PTHREAD_BLOCK;

回答by Trent

The compiler doesn't know that spe_context_ptr_t is a type. Check that the appropriate typedef is in scope when this code is compiled. You may have forgotten to include the appropriate header file.

编译器不知道 spe_context_ptr_t 是一种类型。编译此代码时,请检查适当的 typedef 是否在范围内。您可能忘记包含适当的头文件。

回答by Icegras

I had the same error message but the solution is different.

我有相同的错误消息,但解决方案不同。

The compiler parses the file from top to bottom.

编译器从上到下解析文件。

Make sure a struct is defined BEFORE using it into another:

确保在将结构体用于另一个结构体之前已定义它:

typedef struct
{
    char name[50];
    wheel_t wheels[4]; //wrong, wheel_t is not defined yet
} car_t;

typedef struct
{
    int weight;
} wheel_t;

回答by Brad

For iPhone cocoa-touch projects:

对于 iPhone cocoa-touch 项目:

I had this problem and thanks to Eric Farraro's comment, I was able to get it resolved. I was importing a class WSHelper.h in many of my other classes. But I also was importing some of those same classes in my WSHelper.h (circular like Eric said). So, to fix this I moved the imports from my WSHelper.h file to my WSHelper.m file as they weren't really needed in the .h file anyway.

我遇到了这个问题,多亏了 Eric Farraro 的评论,我才得以解决。我在许多其他类中导入了一个类 WSHelper.h。但我也在我的 WSHelper.h(如 Eric 所说的循环)中导入了一些相同的类。所以,为了解决这个问题,我将导入从我的 WSHelper.h 文件移到了我的 WSHelper.m 文件,因为它们在 .h 文件中并不是真正需要的。

回答by Daniel

I got it with an import loop:

我通过导入循环得到了它:

---FILE B.h
#import "A.h"
@interface B{
  A *a;
}
@end

---FILE A.h
#import "B.h"
@interface A{      
}
@end

回答by Ryan

I was able to sort this out using Gorgando's fix, but instead of moving imports away, I commented each out individually, built the app, then edited accordingly until I got rid of them.

我能够使用 Gorgando 的修复程序解决这个问题,但我没有将导入移走,而是单独评论每个,构建应用程序,然后进行相应的编辑,直到我摆脱它们。

回答by Typen

You have to name your struct like that:

你必须像这样命名你的结构:

typedef struct car_t {

   char

   wheel_t

} car_t;

回答by newbie

this error basically comes when you use the object before using it.

当您在使用对象之前使用它时,基本上会出现此错误。