2010-04-27 8 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())는 입니다.입니다.

당신은

+0

OMG !!! 나는 이것을 볼 수있는 기회가 없었다 :) 고마워. – jackhab

11

당신은 CConfFile::와 두 번째 기능 범위하지 않았습니다. 이 함수는 자유 함수로 컴파일되므로 GetString에 대한 호출이 네 개의 매개 변수를 필요로하는 (재귀 적으로) 해결됩니다.

0

내가 때문에 그 함수를 호출 할 CConfFile 인스턴스를 가지고 있지입니다 말할 것 ... 두 번째 기능에 CConFile::를 추가하는 것을 잊었다, 그래서 당신이 다른 하나를 호출하는 가정합니다.

관련 문제