View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# 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.

5 replies to this topic

### #1Arcand  Members

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.

### #2BCullis  Members

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 (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

### #3Arcand  Members

Posted 04 January 2013 - 04:56 PM

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

### #4kidman171  Members

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.

### #5Arcand  Members

Posted 04 January 2013 - 08:06 PM

### #6MarkS  Members

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.