Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

how to add to vector ( int[2] )

This topic is 5491 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

hi ive got: vector<int[2]> num; And I can't work out how to add variables to it eg. num.push_back({2,2}); so... num[0][0] num[0][1] num[1][0] num[1][1] num[2][0] num[2][1] num[3][0] num[3][1] num[4][0] num[4][1] thanks

Share this post


Link to post
Share on other sites
Advertisement
I've never seen vector attempted to be used like that. That's impressive. Of course it's an evil, naughty, and possibly fattening thing to do, but I can't think of the exact reason why. There's probably chapter-and-verse why you can't do it this way, and I think that it's probably in the area of the type T you're trying to make a container of needs to be referencable and have copy ctors, etc.

Yeah, this is a very, very bad thing to do.

You might make a vector of pair<int,int> or vector< vector<int> > and individually resize each guy.

Share this post


Link to post
Share on other sites
Sure, but that makes an array of two vectors of ints, rather than a vector of arrays of two ints. :)

Try using vector<int *>, and .push_back(new int[2]). You'll have some extra memory overhead, but it should work and be fairly easy to understand what's going on... :/

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!