我有一个类和两种方法:
public:
bool Search ( const string & oName, const string & oAddr,
string & cName, string & cAddr ) const
{
Company ctmp;
ctmp.own = oName + "|" + oAddr;
int place = searchDupl(ctmp,currentsize,0);
if (place < 0)
return false;
else
{
size_t pos = c[place].cmpn.find(' ');
cName = c[place].cmpn.substr(0,pos);
cAddr = c[place].cmpn.substr(pos+1);
return true;
}
}
私下里,我有 searchDupl:
int searchDupl(Company cmp,int imax,int imin)
{
if (imax < imin)
return -1;
else
{
int mid = imin + ((imax - imin)/2);
if (c[mid].own > cmp.own)
{
return searchDupl(cmp,mid-1,imin);
}
else if (c[mid].own < cmp.own)
{
return searchDupl(cmp,imax,mid+1);
}
else
{
return mid;
}
}
}
c 是一个动态数组,在私有部分中定义并在构造函数中初始化。currentsize 是 int 类型的变量(也是私有的并在构造函数中初始化),它定义了 c 中元素的数量。
当我尝试使用 g++ 编译它时,出现以下错误:
main.cpp: In member function ‘bool CCompanyIndex::Search(const string&, const string&, std::string&, std::string&) const’:
main.cpp:69:54: error: no matching function for call to ‘CCompanyIndex::searchDupl(Company&, const int&, int) const’
main.cpp:69:54: note: candidate is:
main.cpp:106:13: note: int CCompanyIndex::searchDupl(Company, int, int) <near match>
main.cpp:106:13: note: no known conversion for implicit ‘this’ parameter from ‘const CCompanyIndex* const’ to ‘CCompanyIndex*’
我不知道出了什么问题。