Why does this overload function not work?

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

Why am I getting an error too few arguments to function ‘void GetString(const std::string&, const std::string&, char*, unsigned int)'in the second function?

thank

+3
source share
3 answers

Because CConFile::GetString(), as the name implies, it offers a member function of a class that is not available as you call it in the second function. Another function you declare GetString()is global .

You just forgot to add CConFile::to the second function ...

+3
source

You did not specify the second function with CConfFile::. It compiles as a free function, so the call GetStringresolves itself (recursively), which requires four parameters.

+11

I would say that this is due to the lack of an instance of CConfFile to call this function, so it is assumed that you are calling another.

0
source

Source: https://habr.com/ru/post/1742975/


All Articles