Array of classes.

Back to topics list To post a new topic, please log in or register
avatar
3
nerotech 2015.04.06 04:25
 

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.

class cBase {
   protected:
      sParameters m_param;
     
   private:
      double m_lotSize;          //lotsize dynamic - calculate based on account size.
      double m_perTrade;       //percent per trade of total account to use.
      double m_balance;         //Account balance
      double m_startHedge;    //Negative pips to start hedging from.
      
   private:
      void setLotSize();
     
   public:
      void setUp(void);             //Setup constant variables across all currencies.
      void PlaceOrder(void);      //Place Order for currency.
      void getOrder(void);        //Gets order for further processing.
      void getPipCount(void);   //Gets current positive/negative pip difference between opening price.
};


/****************************************************************************************************
*Title: cEurUsd : cBase
*Desc:  EURUSD
*Notes: Default: BUY, Hedge: SELL.
****************************************************************************************************/
class cEurUsd : public cBase {
   public:
      cEurUsd(void);
};

cEurUsd::cEurUsd(void) {
   this.m_param.p_sSymbol              = "EURUSD";  //Set currency symbol
   this.m_param.p_iOrderType          = BUY;       //Default to long
   this.m_param.p_iOrderTypeHedge = SELL;      //hedge to short
}
/****************************************************************************************************
****************************************************************************************************/


/****************************************************************************************************
*Title:  cAudJpy : cBase
*Desc:  AUDJPY
*Notes: Default: BUY, Hedge: SELL.
****************************************************************************************************/
class cAudJpy : public cBase {
   public:
      cAudJpy(void);
};

cAudJpy::cAudJpy(void) {
   this.m_param.p_sSymbol           = "AUDJPY"; //Set currency symbol.
   this.m_param.p_iOrderType        = BUY;      //detaul to long.
   this.m_param.p_iOrderTypeHedge   = SELL;     //hedge to short.
}
/****************************************************************************************************
****************************************************************************************************/


/****************************************************************************************************
*Title: cUsdCad : cBase
*Desc:  USDCAD
*Notes: Default: BUY, Hedge: SELL.
****************************************************************************************************/
class cUsdCad : public cBase {
   public:
      cUsdCad(void);
};

cUsdCad::cUsdCad(void) {
   this.m_param.p_sSymbol           = "USDCAD"; //Set currency symbol.
   this.m_param.p_iOrderType        = BUY;      //detaul to long.
   this.m_param.p_iOrderTypeHedge   = SELL;     //hedge to short. 
}
/****************************************************************************************************
****************************************************************************************************/


/****************************************************************************************************
*Title: cAudJpy : cBase
*Desc:  AUDJPY
*Notes: Default: BUY, Hedge: SELL.
****************************************************************************************************/
class cGbpAud : public cBase {
   public:
      cGbpAud(void);
  
};

cGbpAud::cGbpAud(void) {
   this.m_param.p_sSymbol           = "GBPAUD"; //set currency symbol.
   this.m_param.p_iOrderType        = BUY;
   this.m_param.p_iOrderTypeHedge   = SELL;
}
/****************************************************************************************************
****************************************************************************************************/


/****************************************************************************************************
*Title: cNzdChf : cBase
*Desc:  NZDCHF
*Notes: Default: BUY, Hedge: SELL.
****************************************************************************************************/
class cNzdChf : public cBase {
   //buy
   public:
      cNzdChf(void);
};

cNzdChf::cNzdChf(void) {
   this.m_param.p_sSymbol           = "NZDCHF";
   this.m_param.p_iOrderType        = BUY;
   this.m_param.p_iOrderTypeHedge   = SELL;
}
/****************************************************************************************************
****************************************************************************************************/


/****************************************************************************************************
*Title: cGbpJpy : cBase
*Desc:  GBPJPY
*Notes: Default: SELL, Hedge: BUY.
****************************************************************************************************/
class cGbpJpy : public cBase {
   public:
      cGbpJpy(void);
};

cGbpJpy::cGbpJpy(void){
   this.m_param.p_sSymbol           = "GBPJPY";
   this.m_param.p_iOrderType        = SELL;
   this.m_param.p_iOrderTypeHedge   = BUY;
}
/****************************************************************************************************
****************************************************************************************************/


/****************************************************************************************************
*Title: cEurChf : cBase
*Desc:  NZDCHF
*Notes: Default: SELL, Hedge: BUY.
****************************************************************************************************/
class cEurChf : public cBase {
   public:
      cEurChf(void);
};

cEurChf::cEurChf(void){
   this.m_param.p_sSymbol           = "EURCHF";
   this.m_param.p_iOrderType        = SELL;
   this.m_param.p_iOrderTypeHedge   = BUY;
}
/****************************************************************************************************
****************************************************************************************************/


/****************************************************************************************************
*Title: cNzdChf : cBase
*Desc:  NZDCHF
*Notes: n/a.
****************************************************************************************************/
class cNzdCad : public cBase {
   public:
      cNzdCad(void);
};

cNzdCad::cNzdCad(void) {
   this.m_param.p_sSymbol           = "NZDCHF";
   this.m_param.p_iOrderType        = SELL;
   this.m_param.p_iOrderTypeHedge   = BUY;
}
/****************************************************************************************************
****************************************************************************************************/

/****************************************************************************************************
*Title: cCurrency
*Desc:  Main currency class.
*Notes: n/a.
****************************************************************************************************/
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;


Regards,

Nero.

avatar
3
nerotech 2015.04.06 05:09 #
 

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.

avatar
12998
WHRoeder 2015.04.06 14:21 #
 
nerotech: Seems that I should be using a pointer to achieve this? Please advise If I've done this correctly. Thank you.
  1. Yes
  2. Use SRC for code
avatar
3
nerotech 2015.04.07 01:16 #
 
WHRoeder:
nerotech: Seems that I should be using a pointer to achieve this? Please advise If I've done this correctly. Thank you.
  1. Yes
  2. Use SRC for code

Thanks for your confirmation WHRoeder,


Updated first post using "SRC", accidentally inserted using Table?


Regards,

Nero.

Back to topics list  

To add comments, please log in or register