stl::vector as a function parameter
I have a vector that I want to pass as a parameter to a function.
But when I try to compile this:
void increaseVector( vector<cTest>& vec )
{
//code to increase vector
}
the compiler gives these errors:
error C2061: syntax error : identifier 'vector'
warning C4018: '<' : signed/unsigned mismatch
Isn't that the right syntax for passing a vector of cTest objects as a reference?
If I can declare a vector like that, why can't I use it like a type when indicating the type of the function parameter?
Note: I have include #include <vector> at the top.
Thanks in advance
Did you try changing the first line of the function to:
void increaseVector( std::vector<cTest>& vec )
you probably need to write "std::vector<..." instead of just "vector<..."
[Edit] 2 seconds late ;P
[Edit] 2 seconds late ;P
It should probably be
#include <vector>
void increaseVector ( std::vector<cTest> &vec )
{
// codes
}
But your function name makes me wonder what that function does anyway. Seems like you would be making some wrapper
over .reserve or .resize or something strange.
[edit] 4 sec too late. :(
#include <vector>
void increaseVector ( std::vector<cTest> &vec )
{
// codes
}
But your function name makes me wonder what that function does anyway. Seems like you would be making some wrapper
over .reserve or .resize or something strange.
[edit] 4 sec too late. :(
Quote:Original post by spitzervx
it works!
thanks everybody
Everything from the standard C++ headers is in namespace std, so you use std::vector, std::string, std::cout, and so on.
What are you trying to do in increaseVector? Do you know the full std::vector API? Maybe you're trying to do something that's already supported by it. Here's a website that explains the complete interface of std::vector:
http://www.cppreference.com/cppvector/index.html
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement