# stl::vector as a function parameter

This topic is 3932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
Did you try changing the first line of the function to:
void increaseVector( std::vector<cTest>& vec )

##### Share on other sites
you probably need to write "std::vector<..." instead of just "vector<..."

 2 seconds late ;P

##### Share on other sites
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.

 4 sec too late. :(

it works!
thanks everybody

##### Share on other sites
Quote:
 Original post by spitzervxit 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

1. 1
Rutin
21
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 13
• 38
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631715
• Total Posts
3001864
×