问题描述
我无法弄清楚这是什么实际问题。
I can't figure out what the actual problem is with this.
typedef struct _actor
{
...
} _actor, Actor;
class Actor
{
...
};
我得到这个奇怪的错误信息 actor.cpp:31:error:using typedef-name'Actor'after'class'
。
I get this weird error message actor.cpp:31: error: using typedef-name ‘Actor’ after ‘class’
.
任何想法我在这里做错了什么?谢谢:)
Any idea what I did wrong here? Thank you :)
推荐答案
不允许定义符号 Actor
不止一次。 typedef
语句已定义作为
的别名的符号
在尝试声明一个具有相同名称的类之前。 Actor
struct _actor
You are not allowed to define the symbol Actor
more than once. The typedef
statement already defines the symbol Actor
as an alias for struct _actor
before you attempt to declare a class with the same name.
我猜你正在使用 gcc
编译器。在使用 gcc
编译时,会出现以下错误:
I'm guessing you're using the gcc
compiler. I get the following errors when I compile with gcc
:
../src/main.cpp:113: error: using typedef-name ‘Actor’ after ‘class’
../src/main.cpp:111: error: ‘Actor’ has a previous declaration here
第一条消息(指向 class Actor
程序)声明,你不能声明一个类与 typedef名称
( Actor
已声明使用 typedef
)。第二个消息(指向程序中的 typedef struct _actor
行)稍微清楚一些,指的是 Actor
。
The first message (pointing the class Actor
line in the program) states that you cannot declare a class with a typedef-name
(Actor
is already declared using typedef
). The second message (pointing to the typedef struct _actor
line in the program) is a little clearer and refers to the multiple declarations for Actor
.
在C / C ++中,对于类似这样的单一类错误导致多个编译器错误是非常常见的,通常更有帮助的消息不是第一次报告。
It is very common in C/C++ for a single class of error like this to result in multiple compiler errors and often the more helpful message is not the first reported.
这篇关于错误:类后使用typedef名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!