我有以下代码可以正常工作:
list <Politician> MakeList ( int num, ... ){
va_list arguments;
va_start ( arguments, num );
list <Politician> PoliticianList;
for ( int x = 0; x < num; x++ ) {
PoliticianList.push_back(va_arg (arguments, Politician));
}
va_end ( arguments );
return PoliticianList;
}
但是,当试图使其通用时:
template<class TYPE>
list <TYPE> MakeList ( int num, ... ){
va_list arguments;
va_start ( arguments, num );
list <TYPE> PoliticianList;
for ( int x = 0; x < num; x++ ) {
PoliticianList.push_back(va_arg (arguments, TYPE));
}
va_end ( arguments );
return PoliticianList;
}
编译时出现以下错误:
error C2783: 'std::list<TYPE> MakeList(int,...)' : could not deduce template argument for 'TYPE'
我怎样才能使它通用,所以我不必为不同的类对象重新实现?