我希望能够创建一个函数,在该函数中指定一个参数以同时为该容器提供模板化容器和模板化元素类型。这可能吗?我收到“错误C2988:不可模仿的模板声明/定义”等等。这是有问题的功能。C++模板 - 指定容器类型和它容纳的容器元素类型
template<class Iter, class Elem>
void readIntoP(Iter<Elem> aCont){
ifstream ifss("data.dat");
string aString;
int counter = 0;
item tempItem;
while(ifss >> aString){
istringstream iss(aString);
if(counter == 0){
tempItem.name = aString;
}else if(counter == 1){
int aNum = 0;
iss >> aNum;
tempItem.iid = aNum;
}else{
double aNum = 0;
iss >> aNum;
tempItem.value = aNum;
aCont.push_back(tempItem);
counter = -1;
}
++counter;
}
}
重复排序-的[C++函数模板编译错误“‘containerType’不是一个模板” ](http://stackoverflow.com/questions/3436518/c-function-template-compiles-error-containertype-is-not-a-template)(解决方案至少是完全相同的)。 – 2010-08-11 00:03:03