Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Request / Listing] [C++] Arrays inside of arrays?  (Read 2022 times)

0 Members and 1 Guest are viewing this topic.
[Request / Listing] [C++] Arrays inside of array...
« on: May 10, 2006, 10:42:25 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 221
Is it possible in C++ to have arrays inside of arrays? Like, in Sphere, you could do:

Code: [Select]
var MyArray = new Array();

MyArray[0] = new Object();
MyArray[0].OtherArray = new Array();
MyArray[0].OtherArray[0] = "Bob Dole";
MyArray[0].OtherArray[1] = "Chuck Norris";

MyArray[1] = new Object();
MyArray[1].OtherArray = new Array();
MyArray[1].OtherArray[0] = "Cookies";
MyArray[1].OtherArray[1] = "Brownies";

You know what I mean? It's like an array of arrays. How can you do that in C++?
« Last Edit: February 24, 2012, 06:30:01 pm by Niek »
Logged
Re: [C++] Arrays inside of arrays?
« Reply #1 on: May 11, 2006, 06:40:24 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629

Multi-dimensions array?
char* MyArray[5][5] ?

Structure array?
struct MyArray {
      char* Data[5];
      MyArray SecondArray;
}?


Logged
Re: [C++] Arrays inside of arrays?
« Reply #2 on: May 11, 2006, 04:53:01 pm »
  • The Broken King
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1259
You could also do it with an array of integers, and then have each integer be a pointer to another array.
Logged
  • Broken Kings [Temp Site]

aab

^ Evolved from a Hobbit
Re: [C++] Arrays inside of arrays?
« Reply #3 on: May 11, 2006, 05:49:02 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 992
Thats effectively what MyArray[5][5] does, only as an array of pointers where each pointer is the pointer to the first element in the array (which is what any array identifier can be used for).
Better off using pointers than casting integers as you can increment to iterate through no matter what the size of the object, withought a whole load of casting in the way.
Logged




I ♥ Sol
.... I ♥ Sol ? wtf how long has that been there? >_> *rrrrrrrrar*
  • MySpace
Re: [C++] Arrays inside of arrays?
« Reply #4 on: May 12, 2006, 01:00:48 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 221
Thanks!
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.089 seconds with 47 queries.

anything