나는이 있습니다재귀 문제 과부하 운영자
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입니다, 아니 도메인 이름!
의견이 있으십니까?