我想知道是否可以使用 typedef 容器作为模板参数。我正在尝试以下操作:
template<typename T>
using containerT = std::vector<T>;
template <template<class T, class = std::allocator<T> > class container_type = containerT >
struct nodeData {
container_type<int> param;
};
int main()
{
nodeData<> nd;
}
这会导致 GCC 4.8 出现编译错误:
expected a template of type 'template class container_type', got 'template using containerT = std::vector< T >'
有人知道这样做的方法吗?
谢谢
最佳答案
containerT
只有一个模板参数,所以template模板参数必须匹配:
template <template<class> class container_type = containerT >
但是,我怀疑您希望能够将标准容器作为模板参数,所以您希望这样:
template<class T, class Allocator = std::allocator<T>>
using containerT = std::vector<T, Allocator>;
现在您可以使用 containerT
作为您在问题中提供的函数模板的模板参数。
关于c++ - typedef 的 STL 容器类型作为模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24274056/