extra qualification error in C++

后端 未结 5 1431
轮回少年
轮回少年 2020-11-30 01:37

I have a member function that is defined as follows:

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

When

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 02:13

    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.

提交回复
热议问题