extra qualification error in C++

189,016

Solution 1

This is because you have the following code:

class JSONDeserializer
{
    Value JSONDeserializer::ParseValue(TDR type, const json_string& valueString);
};

This is not valid C++ but Visual Studio seems to accept it. You need to change it to the following code to be able to compile it with a standard compliant compiler (gcc is more compliant to the standard on this point).

class JSONDeserializer
{
    Value ParseValue(TDR type, const json_string& valueString);
};

The error come from the fact that JSONDeserializer::ParseValue is a qualified name (a name with a namespace qualification), and such a name is forbidden as a method name in a class.

Solution 2

This means a class is redundantly mentioned with a class function. Try removing JSONDeserializer::

Solution 3

Are you putting this line inside the class declaration? In that case you should remove the JSONDeserializer::.

Solution 4

A worthy note for readability/maintainability:

You can keep the JSONDeserializer:: qualifier with the definition in your implementation file (*.cpp).

As long as your in-class declaration (as mentioned by others) does not have the qualifier, g++/gcc will play nice.

For example:

In myFile.h:

class JSONDeserializer
{
    Value ParseValue(TDR type, const json_string& valueString);
};

And in myFile.cpp:

Value JSONDeserializer::ParseValue(TDR type, const json_string& valueString)
{
    do_something(type, valueString);
}

When myFile.cpp implements methods from many classes, it helps to know who belongs to who, just by looking at the definition.

Solution 5

I saw this error when my header file was missing closing brackets.

Causing this error:

// Obj.h
class Obj {
public:
    Obj();

Fixing this error:

// Obj.h
class Obj {
public:
    Obj();
};
Share:
189,016
prosseek
Author by

prosseek

A software engineer/programmer/researcher/professor who loves everything about software building. Programming Language: C/C++, D, Java/Groovy/Scala, C#, Objective-C, Python, Ruby, Lisp, Prolog, SQL, Smalltalk, Haskell, F#, OCaml, Erlang/Elixir, Forth, Rebol/Red Programming Tools and environments: Emacs, Eclipse, TextMate, JVM, .NET Programming Methodology: Refactoring, Design Patterns, Agile, eXtreme Computer Science: Algorithm, Compiler, Artificial Intelligence

Updated on October 12, 2021

Comments

  • prosseek
    prosseek over 2 years

    I have a member function that is defined as follows:

    Value JSONDeserializer::ParseValue(TDR type, const json_string& valueString);
    

    When I compile the source, I get:

    error: extra qualification 'JSONDeserializer::' on member 'ParseValue'

    What is this? How do I remove this error?

  • altumano
    altumano over 9 years
    Is there any way to make Visual Studio warn about this?
  • sharptooth
    sharptooth over 9 years
    @altumano: No, but Cppcheck can do that and also detect non-ASCII characters in identifiers which helps maintain code more portable to gcc.
  • altumano
    altumano about 9 years
    @sharptooth: thanks, Cppcheck can indeed detect those errors. There is even a Visual Studio plugin for Cppcheck (but it's buggy and do not detect in all files)
  • sharptooth
    sharptooth about 9 years
    @altumano: Is it this thing github.com/VioletGiraffe/cppcheck-vs-addin ? If so could you please report the bug - that project is quite alive and there's good chance it will be fixed.
  • Len
    Len about 4 years
    Hello from The Future. You can now force MSVC to warn about this, by enabling warning C4596 - docs.microsoft.com/en-us/cpp/error-messages/compiler-warning‌​s/… . I'd go so far as to have it be reported as an error, by adding the compiler switch /we4596
  • Zoe stands with Ukraine
    Zoe stands with Ukraine almost 4 years
    JSONDeserializer:: for the cpp file (or the definition in general) is required. Otherwise, you get an undefined reference. coliru.stacked-crooked.com/a/8f8a0cd3f9db6c94 coliru.stacked-crooked.com/a/6cd1efe94c09d521
  • Marvo
    Marvo over 2 years
    Oh, that's what did it for me. I had the ClazzName:: in my .h file. oops.