C++ 中的额外限定错误

2021-12-31 00:00:00 compiler-errors g++ c++

我有一个成员函数,定义如下:

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

当我编译源代码时,我得到:

<块引用>

错误:成员 'ParseValue' 上的额外限定 'JSONDeserializer::'

这是什么?如何消除此错误?

解决方案

这是因为您有以下代码:

class JSONDeserializer{值 JSONDeserializer::ParseValue(TDR 类型,const json_string& valueString);};

这不是有效的 C++,但 Visual Studio 似乎接受它.您需要将其更改为以下代码,才能使用符合标准的编译器进行编译(在这一点上 gcc 更符合标准).

class JSONDeserializer{值解析值(TDR 类型,const json_string& valueString);};

错误来自于JSONDeserializer::ParseValue 是一个限定名(具有命名空间限定的名称),并且这样的名称在类中被禁止作为方法名.>

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?

解决方案

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.

相关文章