文件.h:
template<class T>
T findSize(T &var){
int *i = 0; //Pointer so that it retains its value after loop finishes.
while(var.empty() != true){
i++;
var.pop_back();
}
cout << i << endl;
return i;
}
template<class T>
T findCapacity(T &var){
//How would I find the capacity?
//This is the reason for the template, the capacity must increment by 10.
//e.g. 10 elements = 20 capacity, 20 capacity, 30 capacity.
//opposed to 1, 2, 4, 8...
return something;
}
我如何从 main.cpp 调用函数:
int temp;
for(int i = 0; i < 50; i++){
cin >> temp; //accepts number inputs from user (50 of them)
vect.push_back(temp);
cout << "Size: " << findSize(vect) << " Capacity: " << findCapacity(vect) << endl;
}
巨大的错误是通过以下方式获得的:(未解决)
findSize(vect)
和
findCapacity(vect)
我上面的模板/调用有什么不正确的?^^^
还有什么是找到容量的正确算法?
如建议的那样,未经编辑的错误: http: //pastebin.com/Qw1GPdkM