class templates in header files

Do class templates only work in c.pp files? My VC++2010, underlines header files declared in header files, this is just strange.
No. There is no such restriction. In fact you should keep all your templates (including their definitions) in headers.
This might be a bug in VC++. If there are compiler errors, post your code.
I can'tn declare vectors in my headerfile, thats my issue
it says "vector is not a valid template", the text below it is underlined (its VC2010 tells its an error)
Last edited on
in my project, vectors can only be declared in the "main.cpp". This seems to be very strange behavior indeed. Does anybody have an explanation?

I'm guessing this might have happen to other people
Last edited on
Are you writing std::vector<datatype> varName;? Are you making sure to include #include <vector> at the top of your code? Do you have an "#ifdef" or "#ifndef" that is preventing anypart of the declaration from executing?
If there are compiler errors, post your code.
Before your compiler gets a look in, the preprocessor takes the contents of every file you include with a #include, and dumps it wholesale into the file in which you include it (i.e. into your cpp file).
Topic archived. No new replies allowed.