Search Results

Search found 1 results on 1 pages for 'user1658731'.

Page 1/1 | 1 

  • How does one create and use a pointer to an array of an unknown number of structures inside a class?

    - by user1658731
    Sorry for the confusing title... I've been playing around with C++, working on a project to parse a game's (Kerbal Space Program) save file so I can modify it and eventually send it over a network. I'm stuck with storing an unknown number of vessels and crew members, so I need to have an array of unknown size. Is this possible? I figured having a pointer to an array would be the way to go. I have: class SaveFileSystem { string version; string UT; int activeVessel; int numCrew; ??? Crews; // !! int numVessels; ??? Vessels; // !! } Where Crews and Vessels should be arrays of structures: struct Crew { string name; //Other stuff }; struct Vessel { string name; //Stuff }; I'm guessing I should have something like: this->Crews = new ???; this->Vessels = new ???; in my constructor to initialize the arrays, and attempt to access it with: this->Crews[0].name = "Ship Number One"; Does this make any sense??? I'd expect the "???"'s to involve a mess of asterisk's, like "*struct (*)Crews" but I have no real idea. I've got normal pointers down and such, but this is a tad over my head... I'd like to access the structures like in the last snippet, but if C++ doesn't like that I could do pointer arithmetic. I've looked into vectors, but I have an unhealthy obsession with efficiency, and it really pains me how you don't know what's going on behind it.

    Read the article

1