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>
usingnamespace 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?
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.
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!