Array of classes.
Hello again,
Seems that I should be using a pointer to achieve this?
Please advise If I've done this correctly. Thank you.
OLD
//OLD class cCurrency { private: cBase Cur[]; public: cCurrency(void); void placeOrder(); //Place order }; cCurrency::cCurrency(void) { //Create currency objects, then copy to Cur[] array of object type cBase for easy looping. Possible?? cEurUsd EU; cAudJpy AJ; //etc.. Cur[0] = EU; Cur[1] = AJ //etc... } //TESTING cCurrency Currency;
NEW
//Use the following class cCurrency { private: cBase *Cur[8]; public: cCurrency(void); void placeOrder(); //Place order }; cCurrency::cCurrency(void) { //Create currency objects, then copy to Cur[] array of object type cBase for easy looping. cEurUsd *EU = new cEurUsd(); cAudJpy *AJ = new cAudJpy(); //etc.. Cur[0] = EU; Cur[1] = AJ //etc... //can now loop through all currency objects with Cur[].. } //Delete pointer objects to free memory in OnDeinit() //TESTING cCurrency Currency;
Regards,
Nero.
nerotech: Seems that I should be using a pointer to achieve this? Please advise If I've done this correctly. Thank you.
|
|
WHRoeder:
nerotech: Seems that I should be using a pointer to achieve this? Please advise If I've done this correctly. Thank you. |
|
Thanks for your confirmation WHRoeder,
Updated first post using "SRC", accidentally inserted using Table?
Regards,
Nero.
Hello,
Hopefully someone will be able to help with my query,
I have a base class, and 8 inherited child classes,
is it possible to create an array of type "base" to store each child object for easy looping,
or would there be a better approach to this?
The cCurrency class is responsible for handling all declared currencies objects.
Thanks in advance.
Regards,
Nero.