| IWishIKnew (460) | |||||
|
I know that with classes you have deconstructors, but is there anything I can use for data structures? EX:
lets call this a small psuedo structure. If I used the same structure address (in other words, I never declare a new instance, I only use 1), and I want to delete all the data in this structure, is there any way other than writeing a function to clear it all/declare defaults? ex code:
don't focus on the code errors in that, I pretty much just wrote that on the spot just now to give you an idea of what I'm currently doing to clear data structures. | |||||
|
Last edited on
|
|||||
| naraku9333 (919) | |
In c++ structs have constructors and destructors too, but the dtor wont be called until the variable goes out of scope or if you call delete on it (if it was allocated with new). For what your doing just reseting the variables to defaults looks like it will make the most sense. I also want to note you shouldn't do this player_ship.levels = vector<levels>(); clearing the vector should be sufficient, your adding unnecessary overhead with ctor and operator= calls.
| |
|
Last edited on
|
|