如何修复错误:未知类型名称“命名空间”

时间:2022-12-11 20:24:16
#ifndef UNO_ACTION_ 
#define UNO_ACTION_
namespace Uno
{
namespace Game
{
    class Game;
}
} // namespace

namespace Uno
{
namespace Action
{
using ::Uno::Game::Game;

class Action
{
public:
    virtual bool isDisposeable() = 0;
    virtual void takeAction(Game* game) = 0;
    virtual ~Action() {}
};

}
}
#endif

I compile these code on ubutun 12.04 and it return to set of error:

我在ubutun 12.04上编译了这些代码,它返回到错误集:

action.h:4:1: error: unknown type name ‘namespace’
action.h:4:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
action.h:8:1: error: unknown type name ‘namespace’
action.h:8:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

I don't know how to solve these errors.

我不知道如何解决这些错误。

2 个解决方案

#1


16  

It sounds like you're trying to compile your C++ code with a C compiler. Trying using g++ instead of gcc and giving your file a C++ extension such as .cpp (rather than .c).

听起来好像您正在尝试使用C编译器编译c++代码。尝试使用g++而不是gcc,并为您的文件提供c++扩展名,比如.cpp(而不是. C)。

#2


-1  

I had a similar issue and found this question but the solutions don't match mine completely, so I'm adding mine here.

我也遇到过类似的问题,我发现了这个问题,但是我的答案和我的不完全匹配,所以我在这里加上我的。

In my case, I was including a header file in .cpp files and .c files. The solution was to split off the namespace part of the header since that was obviously only needed in the .cpp files.

在我的例子中,我在.cpp文件和.c文件中包含了一个头文件。解决方案是分离头部的名称空间部分,因为这显然只需要在.cpp文件中。

#1


16  

It sounds like you're trying to compile your C++ code with a C compiler. Trying using g++ instead of gcc and giving your file a C++ extension such as .cpp (rather than .c).

听起来好像您正在尝试使用C编译器编译c++代码。尝试使用g++而不是gcc,并为您的文件提供c++扩展名,比如.cpp(而不是. C)。

#2


-1  

I had a similar issue and found this question but the solutions don't match mine completely, so I'm adding mine here.

我也遇到过类似的问题,我发现了这个问题,但是我的答案和我的不完全匹配,所以我在这里加上我的。

In my case, I was including a header file in .cpp files and .c files. The solution was to split off the namespace part of the header since that was obviously only needed in the .cpp files.

在我的例子中,我在.cpp文件和.c文件中包含了一个头文件。解决方案是分离头部的名称空间部分,因为这显然只需要在.cpp文件中。