2010-04-27 107 views
3
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()); 
} 

为什么我在第二个函数中得到一个错误too few arguments to function ‘void GetString(const std::string&, const std::string&, char*, unsigned int)'为什么这个函数重载不起作用?

感谢

回答

3

因为CConFile::GetString()正如名字所暗示的那样是一个类成员函数,在第二个函数中不能访问它。 您声明的其他功能,GetString(),是一个全球之一。

你只是忘了添加CConFile::至第二个功能...

+0

OMG !!!没有机会我可以看到这个:)谢谢。 – jackhab 2010-04-27 12:14:02

11

你有没有范围的第二功能与CConfFile::。它正在编译为一个自由函数,所以对GetString的调用会自动解析(递归),这需要四个参数。

0

我会说这是因为没有一个CConfFile实例调用该函数,因此它是假设您呼叫的另一方。

相关问题