【发布时间】:2010-08-10 23:58:08
【问题描述】:
我希望能够创建一个函数,在其中我指定一个参数以同时具有模板化容器和该容器的模板化元素类型。这可能吗?我收到“错误 C2988:无法识别的模板声明/定义”等。这是有问题的函数。
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++ function template compiles error "‘containerType’ is not a template" 的重复排序(至少解决方案完全相同)。
标签: c++ templates stl containers