Sign in to follow this  

stl::vector as a function parameter

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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.

[edit] 4 sec too late. :(

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this