Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

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


Sign up now

seriously newbish question :)

4: Adsense

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   

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.



#2 BCullis   Members   

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


#3 Arcand   Members   

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   

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   

11
Like
0Likes
Like

Posted 04 January 2013 - 08:06 PM

:) glad I asked. Thank you very much



#6 MarkS   Members   

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