std::ostream
için genel bir operator<<
ve herhangi bir yinelenen tür oluşturmaya çalışıyorum. C++ şablon operatörü eşleşme olarak bulunamadı
Bu
kodudur:template <class T,template<class> class Iterable> inline std::ostream& operator<<(std::ostream& s,const Iterable<T>& iter){
s << "[ ";
bool first=false;
for(T& e : iter){
if(first){
first=false;
s << e;
}else{
s << ", " << e;
}
}
s << " ]";
return s;
}
Ne yazık ki benim operatör bir
vector<uint>
için bir eşleşme olarak bulunmazsa ve derleyici
operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
ile eşleştirmeye çalışır.
Tanınacak aşırı yükü nasıl değiştirebilirim?
Başka sorun olmayan bir const 'T' ile bir 'const' kap yineleme deneyin olmasıdır. Bunun yerine 'T &&' veya 'T const &' kullanın. –
Ayrıca gerçek –