I am getting these errors but I can't figure out why. I know it has something to do with the .h file but I am stumped, thanks in advance. My error messages are attached.
vector does not belong to the global namespace. Under your includes, add
Code:
using std::vector;
If you do'nt add that using statement (or the more general [but less desirable] using namespace std then you must qualify your use of vector by its namespace:
Code:
void printarray(std::vector<int>* invector);
A side note, why are you passing a vector by pointer?
=--=--=--=--=--=--=--=--=--=--=--=--=--=
Please rate this post to show your appreciation for those that helped you.
stdafx.h file not a good place put your function declarations. Besides for the current code layout, you dont even need a declaration since you are defining the function print function before it is being called/invokded and is fully visible to the compiler.
Regards,
Usman.
P.S: Code Tags???
Last edited by usman999_1; October 9th, 2007 at 09:09 AM.
vector does not belong to the global namespace. Under your includes, add
Code:
using std::vector;
If you do'nt add that using statement (or the more general [but less desirable] using namespace std then you must qualify your use of vector by its namespace:
Code:
void printarray(std::vector<int>* invector);
A side note, why are you passing a vector by pointer?
First off I am a novice with C++, if it wasn't obvious
I don't think I am passing by pointer. I am passing a vector to the prinarray method, and then assigning invector as the pointer to the vector. Please correct me if that is not true, thanks for your reply.
You are passing it by pointer.... that's what the * is, and that's why your calls to the invector at method were using the -> opeartor.
So when you call your method, you're calling it like
Code:
printarray (&FA);
printarray (&SA);
The & is to get the address (pointer) of the vector. You can greatly simplify your code by a) passing in by reference b) passing that reference const (const means constant meaning you're not modifying the data, only reading it) c) using iterators to iterate your data instead of indexes (which is what you were doing with the at method call).
=--=--=--=--=--=--=--=--=--=--=--=--=--=
Please rate this post to show your appreciation for those that helped you.
Well, with all the codes/projects I've looked at in the few years that I've been working with Visual C++, none of the projects used stdafx.h for function declarations, this is more like not a rule but something like a good practice.
You can have all the code of your project in a single cpp file , but if that makes sense is a moot point .
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.