为什么这个函数重载不起作用?

jac*_*hab 3 c++ overloading

class CConfFile
{
    public:
        CConfFile(const std::string &FileName);
        ~CConfFile();
        ...
        std::string GetString(const std::string &Section, const std::string &Key);
        void GetString(const std::string &Section, const std::string &Key, char *Buffer, unsigned int BufferSize);
        ...
}

string CConfFile::GetString(const string &Section, const string &Key)
{
    return GetKeyValue(Section, Key);
}

void GetString(const string &Section, const string &Key, char *Buffer, unsigned int BufferSize)
{
    string Str = GetString(Section, Key);     // *** ERROR ***
    strncpy(Buffer, Str.c_str(), Str.size());
}
Run Code Online (Sandbox Code Playgroud)

为什么我too few arguments to function ‘void GetString(const std::string&, const std::string&, char*, unsigned int)'在第二个函数出错?

谢谢

Mar*_*tos 11

你没有使用第二个函数CConfFile::.它被编译为自由函数,因此调用GetString解析为自身(递归),这需要四个参数.