I am trying to use a pointer to an array of custom objects in C++. The following code compiles and runs fine on eclipse which uses a gnu compiler from cygwin. But the code gives compilation errors in Visual Studio.
Error
class 'Levels' has an illegal zero-sized array
on line
Structure *mStructres[];
COMPLETE CODE
/*
* Levels.h
*/
#include "objects/Structure.h"
#ifndef LEVELS_H_
#define LEVELS_H_
class Levels{
public:
//other public members
void reInitialize();
Levels();
~Levels();
private:
//other private members
Structure *mStructres[];
};
#endif /* LEVELS_H_ */
/////////////////////////////////////
/*
* Levels.cpp
*/
#include "Levels.h"
Levels::Levels() {
}
Levels::~Levels() {
}
void Levels::reInitialize() {
mStructres[size];
for (int i = 0; i < jStructeresArr.size(); i++) {
mStructres[i] = new Structure(obj1, obj2,
obj3);
}
}
I tried changing the line to
Structure *mStructres;
but then I got errors on these lines in reinitialize method
mStructres[size];
for (int i = 0; i < jStructeresArr.size(); i++) {
mStructres[i] = new Structure(obj1, obj2,
obj3);
}
What am I doing wrong? Is this the correct way to do it for cross-platform developement?
UPDATE I would prefer not using vectors or std templates at this stage.