I need to read some file into a 2d array. The filesize is unknown, but it can vary from bytes to kylobytes, or more. The actual problem is how to initialize a dynamic 2d array. If I write smth like
float* map;
, then I can't write a function that returns map[j] etc.
The program is planned to be smth like this:
class Map
{
public:
//...
private:
float* map; // or some other way of initialising
};
...
Map::Map( void )
{
// the needed sise of the array is unknown yet
// reading the file, calculating it's size
// map = new something - allocating memory
// using map[j] element
}
I know this is a stoopid question, but I can't figure out how it's done.
float* map;
, then I can't write a function that returns map[j] etc.
The program is planned to be smth like this:
class Map
{
public:
//...
private:
float* map; // or some other way of initialising
};
...
Map::Map( void )
{
// the needed sise of the array is unknown yet
// reading the file, calculating it's size
// map = new something - allocating memory
// using map[j] element
}
I know this is a stoopid question, but I can't figure out how it's done.