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
}
Редактировать: после первого комментария
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*()
}
Приведенный выше код показывает частичное упорядочение и разрешение перегрузки, когда оба шаблона / не шаблон.