Additional qualification error in C ++

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: additional qualification "JSONDeserializer ::" in the ParseValue member

What is it? How to remove this error?

+72
c ++ g ++ compiler-errors
Apr 12 2018-11-21T00:
source share
4 answers

This is because you have the following code:

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

This is invalid C ++, but Visual Studio seems to accept it. You must change it to the following code in order to be able to compile it using the standard compiler (gcc is more consistent with the standard at this point).

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

The error occurs because JSONDeserializer::ParseValue is a qualified name (a name with a qualified namespace), and such a name is forbidden as the name of a method in the class.

+135
Apr 12 2018-11-11T00:
source share

This means that the class is excessively referenced using the class function. Try to remove JSONDeserializer::

+15
Apr 12 2018-11-21T00:
source share

Do you put this line inside the class declaration? In this case, you must remove JSONDeserializer:: .

+11
Apr 12 '11 at 22:30
source share

A decent note for readability:

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

As long as your class declaration (as others have mentioned) has no qualifier, g ++ / gcc will play well.

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 find out who belongs to whom simply by looking at the definition.

+5
Apr 24 '15 at 20:47
source share



All Articles