Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Ubermeowmix

Member Since 30 Jan 2010
Offline Last Active Today, 10:21 AM
-----

Posts I've Made

In Topic: C++ create an array of nested class objects in a class

Today, 05:03 AM

Oh that's great news, I was reading one website that said .bin files don't really like vectors. Is it stable enough to use in games saves for release titles?

 

Thanks again guys, you've cleared up quite a few things there.


In Topic: C++ create an array of nested class objects in a class

Yesterday, 06:37 PM

That's great ta:

Firstly I was just trying to encapsulate the code as it seemed the natural progression if I were creating objects in objects. Is it wrong to try this kind of nesting? Would I be better off just creating a separate class?

Secondly I was trying to avoid vectors as I thought that you couldn't save them in .bin files. only vars and arrays! Is that a falsehood?

In Topic: C++ create an array of nested class objects in a class

Yesterday, 04:08 PM

You should only delete what you have created with new.

So for the following line how do I reference back to this object once created? or do I just assign the array slot to zero?
GenObjectClass::mcaTroops[i] = new GenObjectClass::cTroopObj;

Is mcaTroops supposed to be static, meaning it only exists one such array that will stay alive until the end of the program, or do you want each GenObjectClass to have its own mcaTroops array?

Ah I seem to have mistaken the use of static then, I didn't realise it was till program death, I thought it was in the scope of the objects lifespan.

yes, each GenObjectClass to have its own mcaTroops array.

In Topic: C++ create an array of nested class objects in a class

Yesterday, 05:22 AM

I want an array of nested class objects to be stored in the main class objects array, they are then created and detroyed by the function calls of the class they are nested in.

Troop
TroopContainer
*Container<Troop>
*addTroop(Troop troop)


In Topic: C++ create an array of nested class objects in a class

Yesterday, 05:20 AM

Awesome thanks guys.

Just a few last questions, do I need to "delete mcaTroops;" in the destructor?
As soon as I use a pointer the memory is allocated on the heap isn't it, will it stay in scope whilst the GenObjectClass object; still exists!

And do I need to declare the object as a pointer to keep it 'alive' (GenObjectClass* object;) within the scope of the main function? deleting that when it is also not needed in the code.

PARTNERS