37
battleutils.cpp:1037: error: explicit qualification in declaration of 'int32 battleutils::AbilityBenediction(CBattleEntity*, CBattleEntity*)'

What does this error mean exactly?

The first line here is 1037 (in 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.

2
  • voting to close as "does not contain MCVE", there is nothing wrong with the code as posted
    – M.M
    Commented Jun 11, 2015 at 1:19
  • 1
    One possible way this might have arisen is if you forgot a }, or didn't realize you already had namespace battleutils in the cpp file. For example, namespace N { int f(); int N::f() {} } gives the same error. In this case, the top answer's suggested fix of namespace N { int f(); namespace N { int f() {} } } would hide the error message but actually define a different function N::N::f. I personally prefer to use the explicit qualification in my own code so that an error message is generated if the parameters don't match (instead of overloading or hiding the intended function).
    – M.M
    Commented Jun 11, 2015 at 1:25

3 Answers 3

53

tl;dr: Drop the namespace from before the function name.

I ran into the same issue. I had some source that compiled using MS Visual Studio but using g++ in Linux it gave me:

... 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;}.

Basically, if the implementation (the code in you .cpp file) is already inside namespace foospace {...} then remove foospace:: from the function definition.

0
23

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

error: explicit qualification in declaration of ...

namespace foo {

    // REMOVE THIS "foo::" from here
    void foo::myFunction(int x) {
        // ...
    }

}

It's either missing, multiple times declared or wrong namespace. Coming from other programming languages where namespace system is used a little bit differently, I can see why it is easy to get confused since C++'s classes need to have the classes name defined like this myClass::myMemberFunction(...)

0

Sorry if already mentioned above. I landed here because I've switched from MSVC (Windows) to my Archlinux installation for testing cross-compile effectively.

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.