array with unknown amount of elements

Hello

I've got a class level, which contains an array of a class named Block. It needs to be prototyped in the level class, but at the time, I won't know the amount of elements that the Block has. The following doesn't work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    #ifndef LEVEL_H
    #define LEVEL_H
     
    #include "Block.h"
    #include "MapLoader.h"
     
     
    class level
    {
        public:
            level();
            MapLoader map;
            Block block[][][];
        protected:
        private:
    };
     
    #endif // LEVEL_H 
the amount of elements in the block class is later loaded when the maploader reads the map-file. that will be in the constructor
You use an one-dimensional vector (although in theory, nested vectors could be used) for that and an accessor function that flattens the indices.
Take a look at boost multi_array
Topic archived. No new replies allowed.