struct S{
template<class T> operator T(){return T();}
operator int(){return 0;}
};
int main(){
S s;
int xi = s; // both template and non template are viable. Overload res chooses non tmpl
char xc = s; // both template and non template are viable. Overload res chooses tmpl
}
편집 점, ISO C++ 표준 14.5.2 섹션입니다 : 첫번째 코멘트 후
struct B{
operator int(){return 0;}
};
struct S : B{
template<class T> operator T(){return T();}
operator int(){return 0;}
template<class T> operator T*(){return T();}
};
int main(){
S s;
int xi = s; // Overload reslution between operator T and operator int
char xc = s; // Overload resolution between operator T and operator int
int *pi = s; // Partial ordering involved between operator T() and operator T*()
}
위의 코드는 템플릿/비 템플릿 모두가 관련되어있는 경우 부분 정렬 및 과부하 해결을 보여줍니다.
실수로 작성해야합니다. 발췌 부분은 분명히 영어가 아닙니다. – Borealid
어떤 부분이 당신을 혼란스럽게합니까? "All it it"은 계산되지 않습니다 :) –