C++ 声明中的明确限定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8461832/
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
explicit qualification in declaration
提问by Zeno
battleutils.cpp:1037: error: explicit qualification in declaration of 'int32 battleutils::AbilityBenediction(CBattleEntity*, CBattleEntity*)'
Battleutils.cpp:1037: 错误:'int32 Battleutils::AbilityBenediction(CBattleEntity*, CBattleEntity*)' 声明中的显式限定
What does this error mean exactly?
这个错误究竟是什么意思?
The first line here is 1037 (in battleutils.cpp):
这里的第一行是 1037(在 Battleutils.cpp 中):
int32 battleutils::AbilityBenediction(CBattleEntity* PCaster, CBattleEntity* PTarget)
{
....
return blah;
}
In the header file under:
在头文件下:
namespace battleutils
{
is this:
这是:
int32 AbilityBenediction(CBattleEntity* PCaster, CBattleEntity* PTarget);
The .cpp file correctly includes the header file.
.cpp 文件正确包含头文件。
回答by Benrobot
I ran into the same issue. I had some source that compiled using MS Visual Studio but using g++ in Linux it gave me:
我遇到了同样的问题。我有一些使用 MS Visual Studio 编译的源代码,但在 Linux 中使用 g++ 它给了我:
... error: explicit qualification in declaration of '...
It appears that this error occurs when the implementation is already inside namespace foospace {...}
and the implementation gives the namespace again int foospace::barfunction(int blah){return 17;}
.
当实现已经在内部namespace foospace {...}
并且实现再次提供命名空间时,似乎会发生此错误int foospace::barfunction(int blah){return 17;}
。
Basically, if the implementation (the code in you .cpp file) is already inside namespace foospace {...}
then remove foospace::
from the function definition.
基本上,如果实现(.cpp 文件中的代码)已经在里面,namespace foospace {...}
那么foospace::
从函数定义中删除。
回答by O-9
Well, this is not an answer to this particular question, but because this is the first result on Google search when searching this error message, I just might tell that I got this error message when I had declared twice the namespace (when not needed) - like this
好吧,这不是这个特定问题的答案,但因为这是搜索此错误消息时 Google 搜索的第一个结果,所以我可能会告诉我,当我声明了两次命名空间时(不需要时),我收到了此错误消息- 像这样
error: explicit qualification in declaration of ...
错误:声明中的明确限定...
namespace foo {
// REMOVE THIS "foo::" from here
void foo::myFunction(int x) {
// ...
}
}
Beginner's mistake. Check your namespaces. It's either missing, many times declared or wrong namespace - I would assume.
初学者的错误。检查您的命名空间。它要么丢失,多次声明或错误的命名空间 - 我会假设。
回答by Bretzelus
Sorry if already mentioned above. I landed here because I've switched from MSVC (Windows) to my Archlinux installation for testing cross-compile effectively.
对不起,如果上面已经提到。我来到这里是因为我已经从 MSVC (Windows) 切换到我的 Archlinux 安装来有效地测试交叉编译。
So "Be Aware" that MSVC (Visual Studio) will be permissive using namespace extra qualifications - at least with the /W1 switch (level 1 warnings) thus ignoring the extra qualification (explicit namespace within itself). Notice that either in gcc; clang; msvc, this error does not happen to class members and function parameters and that is what confuses me about that extra qualification error only applied on "unit/file" functions...
所以“注意”MSVC (Visual Studio) 将允许使用命名空间额外限定 - 至少使用 /W1 开关(1 级警告)从而忽略额外限定(自身内的显式命名空间)。请注意,要么在 gcc; 铛; msvc,这个错误不会发生在类成员和函数参数上,这就是让我感到困惑的原因是那个额外的限定错误只适用于“单元/文件”函数......