2010-04-27 91 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實例調用該函數,因此它是假設您呼叫的另一方。