extra qualification error in C++

C++G++Compiler Errors

C++ Problem Overview


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?

C++ Solutions


Solution 1 - C++

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 - C++

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

Solution 3 - C++

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

Solution 4 - C++

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 - C++

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();
};

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionprosseekView Question on Stackoverflow
Solution 1 - C++Sylvain DefresneView Answer on Stackoverflow
Solution 2 - C++joe_coolishView Answer on Stackoverflow
Solution 3 - C++Boaz YanivView Answer on Stackoverflow
Solution 4 - C++bunkerdiveView Answer on Stackoverflow
Solution 5 - C++y.selivonchykView Answer on Stackoverflow