【发布时间】:2018-07-22 04:03:26
【问题描述】:
当我尝试使用我的自定义字符串类作为键值时,我看到了这个错误
undefined reference to `operator<(DSString const&, DSString const&)'
我已经重载了
bool DSString::operator< (const DSString& newData){
bool lessThan = true;
int counter = 0;
int dataLetter = 0;
int newDataLetter = 0;
//compare each letter of both Strings until they differ,
while(dataLetter == newDataLetter && counter < this->length){
dataLetter = static_cast<int>(data[counter]);
newDataLetter = static_cast<int>(newData.data[counter]);
//change bool if char of current stirng is greater
if(dataLetter < newDataLetter)
lessThan = true;
else if (dataLetter > newDataLetter)
lessThan = false;
}
return lessThan;
}
【问题讨论】:
-
"我已经重载了
-
重载的代码是绝对关键的。请edit问题添加。
标签: c++ string dictionary key operator-overloading