Templates on templates

Hello,

This works:
1
2
3
4
#include <vector>
template <typename U>
void doIt(const std::vector<U>& x) {
}


But this does not:

1
2
3
4
template <typename T, typename U>
void doIt(const T<U>& someCollection) {
 //...
}



 
error: 'T' is not a template


WTF?
Last edited on
Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <vector>
#include <list>
using namespace std;

template < template <class> class T, class U >
ostream & print(const T<U> & someCollection)
{
    typename T<U>::const_iterator it;

    it=someCollection.begin();

    while (it!=someCollection.end())
        cout << *it++ << ' ';

    return cout;
}

int main()
{
    vector<int> v;
    list<double> l;

    v.push_back(1); v.push_back(2);
    l.push_back(1.1); l.push_back(2.2);

    print(v) << endl;
    print(l) << endl;

    cin.get();
    return 0;
}

EDIT: Nice try though ;)
Last edited on
Thanks.
Topic archived. No new replies allowed.