我有這樣的:遞歸問題重載操作
typedef string domanin_name;
然後,我嘗試過載這種方式操作<:
bool operator<(const domain_name & left, const domain_name & right){
int pos_label_left = left.find_last_of('.');
int pos_label_right = right.find_last_of('.');
string label_left = left.substr(pos_label_left);
string label_right = right.substr(pos_label_right);
int last_pos_label_left=0, last_pos_label_right=0;
while(pos_label_left!=string::npos && pos_label_right!=string::npos){
if(label_left<label_right) return true;
else if(label_left>label_right) return false;
else{
last_pos_label_left = pos_label_left;
last_pos_label_right = pos_label_right;
pos_label_left = left.find_last_of('.', last_pos_label_left);
pos_label_right = right.find_last_of('.', last_pos_label_left);
label_left = left.substr(pos_label_left, last_pos_label_left);
label_right = right.substr(pos_label_right, last_pos_label_right);
}
}
}
我知道這是超負荷運營商一種奇怪的方式<,但我必須這樣做。它應該做我想要的。那不是重點。
的問題是,它在一個無限循環就在此行中輸入:
if(label_left<label_right) return true;
好像它試圖利用這個重載函數本身做對比,但label_left是串,不是域名!
有什麼建議嗎?