class templates in header files

Feb 20, 2011 at 10:31am
Do class templates only work in c.pp files? My VC++2010, underlines header files declared in header files, this is just strange.
Feb 20, 2011 at 10:36am
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.
Feb 20, 2011 at 10:37am
I can'tn declare vectors in my headerfile, thats my issue
Feb 20, 2011 at 10:39am
it says "vector is not a valid template", the text below it is underlined (its VC2010 tells its an error)
Last edited on Feb 20, 2011 at 10:44am
Feb 20, 2011 at 11:33am
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 Feb 20, 2011 at 11:36am
Feb 20, 2011 at 5:32pm
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?
Feb 20, 2011 at 6:06pm
If there are compiler errors, post your code.
Feb 20, 2011 at 6:25pm
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.