Jump to content

  • Log In with Google      Sign In   
  • Create Account


seriously newbish question :)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Arcand   Members   -  Reputation: 11

Like
0Likes
Like

Posted 04 January 2013 - 04:35 PM

can you encapsulate a vector inside another vector? im trying to make five "rooms" each with nine "sections", that being the 8 directions and the center, but I just realized that I have no idea if I actually can, and if so, how :-), I want to be able to access and modify the strings within the room(section) easily.

 

I hope this makes sense, I am new to programming.

 

thx.



Sponsor:

#2 BCullis   Crossbones+   -  Reputation: 1813

Like
0Likes
Like

Posted 04 January 2013 - 04:55 PM

If you're asking if you can have a "vector of vectors", yes.  Otherwise it just sounds like you're talking about generic data encapsulation.

 

Perhaps you're thinking about a list/vector of Room objects, and each Room object contains a list/vector of Section objects?  That's definitely allowable.  You can nest objects and data many, many levels deep depending on how your object composition is set up.


Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#3 Arcand   Members   -  Reputation: 11

Like
0Likes
Like

Posted 04 January 2013 - 04:56 PM

I just found an answer,

 

vector<vector<string>> room[10];

 

and supposudly to access it one would use sub-brackets such as

 

room[4].resize(9);

 

to make the fourth room a size of 9 or simply

 

room.resize(4); to make four rooms.

 

Confirmation would be great :)



#4 kidman171   Members   -  Reputation: 498

Like
1Likes
Like

Posted 04 January 2013 - 05:43 PM

vector<vector<string>> room[10];

 

 

This code would create an array of 10 vectors of vectors of strings.


I think you want this:

 

vector<vector<string>> room(10);

 

 

This would create an vector of vectors of strings, instantiated with 10 elements.


Edited by kidman171, 04 January 2013 - 05:44 PM.


#5 Arcand   Members   -  Reputation: 11

Like
0Likes
Like

Posted 04 January 2013 - 08:06 PM

:) glad I asked. Thank you very much



#6 MarkS   Prime Members   -  Reputation: 880

Like
0Likes
Like

Posted 05 January 2013 - 11:16 AM

May I ask why you want to use vectors here? If you have five rooms and each room contains nine sections, the added overhead from the dynamic array would be overkill. A simple 2D array would suffice, e.g., string room[5][9];






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS