template template parameter issue
I am wondering what's wrong with template parameter in print()?
I was tring to use print without specifying template argument.
This is the error I got.
error C2784: 'void print(const C<T> &)' : could not deduce template argument for 'const C<T> &' from 'std::vector<_Ty>'
Code:
#include <vector>
#include<iostream>
#include <iterator>
using namespace std;
template<typename T, template<class > class C >
void print(const C<T> &x)
{
copy(x.begin(), x.end(), ostream_iterator<T>(cout," "));
cout << endl;
}
int main()
{
vector<double> v;
v.push_back(100);
print(v);
}
Re: template template parameter issue
For one thing std::vector takes two template arguments (contained type and allocator), so it doesn't match the function argument.
Re: template template parameter issue
Thanks Graham,
Code:
//correct defition
template<typename T, template<class U, class Allocator = allocator<U> > class C>
void print(const C<T> &x)
{
copy(x.begin(), x.end(), ostream_iterator<T>(cout," "));
cout << endl;
}
Sam