vector<> within a template class

Apr 24, 2011 at 3:21pm
I want to have a vector within my own template class, declaring the vector with a specializable type:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

template <typename T1>
class WorkUnit {
private:
	int ID;
	int Priority;
	vector<T1> Input;
};


Unfortunately it brings me:
1
2
ISO C++ forbids declaration of ‘vector’ with no type
error: expected ‘;’ before ‘<’ token


Now I am afraid that it is not possible at all. The reason for having a vector with a template class is that I want to add some more fields (like ID, Priority etc. in my class)

Any idea? Or is it a serious issue to realize that?

Thanks in advance.
Apr 24, 2011 at 3:27pm
#include <vector>
Apr 24, 2011 at 3:27pm
std::vector is defined in the standard header vector, so adding the line
#include <vector>
may solve your problem.

From that error, it looks like the compiler thinks vector is a variable name, and you have forgotten the type (this is why it is then not expecting the '<'). But what you are trying to to is perfectly possible.

Hope this helps.

@Disch Heh you beat me by half a minute ;)
Last edited on Apr 24, 2011 at 3:28pm
Apr 24, 2011 at 3:32pm
Guys, thanks a lot....

If you are doing something really complex (the real code is much more complex than the simplified example, including nested templates and so on ...) then you forget the simplest... ;)

@Xander: Thanks for your further explanations - this makes sense and helps for interpreting compiler-messages in the future!
Topic archived. No new replies allowed.