【发布时间】:2010-05-18 18:43:45
【问题描述】:
我有一个任意 STL 容器 C,其中包含任意类型 T 的元素。我想创建一个 std::vector,它具有所有元素的副本。最干净的方法是什么?
template <typename C>
void myfunction(C container){
/*Derive the type T of elements within the container*/
std::vector<T> mystack;
/* Iterate over container and push_back() the elements into mystack*/
}
【问题讨论】:
标签: c++ templates stl generic-programming