Jump to content
  • Advertisement
Sign in to follow this  
spitzervx

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.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!