I have an iPhone app that used to use an array of several thousand small objects for its data source. Now, I am trying to make it use C++ Structs, to improve performance. I have written the struct, and put it in “Particle.h”:
typedef struct{
double changeX;
double changeY;
double x;
double y;
}ParticleStruct;
Then, I imported “Particle.h”, and attempted to define the array:
#import "Particle.h"
@implementation ParticleDisplay
struct ParticleStruct particles[];
///Size will be determined later, this declaration is to make
////the declaration visible to the entire class...
On this line, however, I get the error: “Array type has incomplete element type”.
Everything else compiles fine, as far as I can tell, and I am sure that “Particle.h” has been imported before the declaration.
Any ideas?
Since you have already
typedefed it in Particle.h, drop the wordstructfrom the array declaration line (the line where the error is).HOWEVER,
In C++, you do not need to
typedefit, just writestruct Particle { /* members */ };Why are you declaring an array without the length? Consider using
std::vector(tutorial) which is a dynamically re-sizeable array (you don’t have to bother about the length ever). It is simple as:std::vector< Particle > particles;