Skip to main content
gamedev.net
🔒 Locked

Dynamicly sized array in c++?

Started by TechnoGoth 2 replies 350+ views
Original Post
TechnoGoth
TechnoGoth
Here is my problem I want to create a 3 dimensional array of a custom class, the size of which will be determined at runtime. now in java there is vector, which If I remember right does this. But does c++ have something like this? If so what header do import and how do I create and use it? Basically I need a data structure that can be used as 3 demenisonal array, it has to allow me to access any element at any time. example call: map[x][y][z].getTileType(); Can anyone help me out? ----------------------------------------------------- Writer, Programer, Cook, I'm a Jack of all Trades Current Design project Chaos Factor Design Document [edited by - TechnoGoth on November 20, 2003 2:59:57 AM]
MARS_999
MARS_999
look up vector. Its a STL feature like string.
Ratterbox
Ratterbox
C++ too Includes a vector template

It works like this


#include <vector>

class CMyClass {
public:
CMyClass() {}

int m_nMyStuff;
};

std::vector<CMyClass> g_cClass;


[edited by - Ratterbox on November 20, 2003 2:54:37 AM]
alnite
alnite
For three dimensional array, I think you need something like this:

std::vector< std::vector< std::vector< MyClass > > > myclassArray;

don't remove the spaces in between. They are there so that the compiler won't mistake them as >> operator.

edit: damn forum tag.

[edited by - alnite on November 20, 2003 4:43:27 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.