-
template C++
I was reading about "template template parameters" and when i try this code out it results in compiler error, can anyone help me out ?
Code:
#include <cstdio>
#include <list>
#include <vector>
#include <string>
using namespace std;
template<template<typename T> class containerType>
class Container
{
containerType < int > intC;
};
int main()
{
Container<vector>vC;
return 0;
}
Compile Error:
Code:
templates.cpp: In function ‘int main()’:
templates.cpp:15: error: type/value mismatch at argument 1 in template parameter list for ‘template<template<class T> class containerType> class Container’
templates.cpp:15: error: expected a template of type ‘template<class T> class containerType’, got ‘template<class _Tp, class _Alloc> class std::vector’
templates.cpp:15: error: invalid type in declaration before ‘;’ token
-
Re
Adding an allocator parameter removes the error
Code:
containerType < int,allocator<int> > intC;
But is there anyway to avoid or make it default or something ?
-
It seems sort of simpler to use a normal template and instantiate a Container<vector<int> >?
-
Code:
template<typename Type>
class Container
{
public:
Container();
};
int _tmain(int argc, _TCHAR* argv[])
{
Container<vector <int> > vC;
return 0;
}
we can see the <vector <int> > as a whole type.