Re: C++ Vector question??
vector does not belong to the global namespace. Under your includes, add
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?
Re: C++ Vector question??
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???
Re: C++ Vector question??
Quote:
Originally Posted by Eli Gassert
vector does not belong to the global namespace. Under your includes, add
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.
Re: C++ Vector question??
Good point, I didn't even think of that. It ran fine when I commented out the method definition in the .h.
Thanks.
Re: C++ Vector question??
Thsi code is untested...
Code:
void printarray (const vector<int> &invector)
{
for(vector<int>::const_iterator i = invector.begin(); i != invector.end(); ++i)
{
cout << *i << endl;
}
}
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).
Re: C++ Vector question??
Quote:
Originally Posted by usman999_1
stdafx.h file not a good place put your function declarations.
Why not?
Re: C++ Vector question??
Quote:
Originally Posted by Arjay
Why not?
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 :D, but if that makes sense is a moot point :).
Regards,
Usman.