static behavioral of non static struct in class !!! - page 2

 
class CBaseCalc
  {
private:

   //int               _period;

public:

   int               _period;
///////////////////////////////////////////
class CCondition : public CBaseCalc
  {
private:

   //int               _period;

public:
                     CCondition(int period):CBaseCalc(period){}
                     //_period(period) {}
///////////////////////////////////////////
class CFirstPullBack : public CStrategy
  {


private:

   //int               _period;
   COHLC             _OHLC;
   double            _price;
   datetime          _time;
   int               _majicknumber;
   bool              Strategy(void);

public:

                     CFirstPullBack(int, int);
   void              SetPrice();
   double            GetPrice(void)                                  { return _price;          }
   //--- Abs func
   double            Factory(void);
   datetime          GetTime(void)                                   { return _time;           }
   int               GetMajick(void)                                 { return _majicknumber;   }
  };
//+------------------------------------------------------------------+
//| Cunstractor                                                      |
//+------------------------------------------------------------------+
CFirstPullBack::CFirstPullBack(int period, int majicknumber):
   //_period(period),
   _majicknumber(majicknumber)
  {
   CCondition(period);
  }
Laszlo Tormasi #
:

Why did you (re)declare _period in each subclass? This way the baseclass variable is not initialized with the correct timeframe. If you create FirstPullBack instances with different timeframes the IsThreeSoldier is still checked on each with _period=0, so all of them will be true at the same time. That's why they called SetPrice simultaneously. 

Do you mean that all subclasses work with the period of the base class and do not need to keep their own instance of the period?

This way ?

 
moslem alavi #:

Do you mean that all subclasses work with the period of the base class and do not need to keep their own instance of the period?

This way ?

//+------------------------------------------------------------------+
class CBaseCalc
  {
private:

   int               _period;

public:
                     CBaseCalc(int period):_period(period) {}
   int               GetPeriod() {return _period;}
  };
///////////////////////////////////////////
class CCondition : public CBaseCalc
  {
private:

public:
                     CCondition(int period):CBaseCalc(period) {}
  };

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CStrategy : public CCondition
  {

public:
                     CStrategy(int period):CCondition(period) {};
  };


///////////////////////////////////////////
class CFirstPullBack : public CStrategy
  {
private:

   int               _majicknumber;

public:

                     CFirstPullBack(int, int);
  };
//+------------------------------------------------------------------+
//| Cunstractor                                                      |
//+------------------------------------------------------------------+
CFirstPullBack::CFirstPullBack(int period, int majicknumber):
   CStrategy(period),
   _majicknumber(majicknumber)
  {
  }
//+------------------------------------------------------------------+

Here you don't call the parent (CCondition) constructor, that is wrong:

//+------------------------------------------------------------------+
//| Cunstractor                                                      |
//+------------------------------------------------------------------+
CFirstPullBack::CFirstPullBack(int period, int majicknumber):
   //_period(period),
   _majicknumber(majicknumber)
  {
   CCondition(period);
  }
 
Laszlo Tormasi #:

Here you don't call the parent (CCondition) constructor, that is wrong:

So, how should First Pull Back set its period Condition?
 

It was solved in another way, but I still don't understand what the problem was!

Thank you for your time

 
moslem alavi #:

It was solved in another way, but I still don't understand what the problem was!

Thank you for your time

Really ? and how ? Please share your solution when people tried to help you.

 
Alain Verleyen #:

Really ? and how ? Please share your solution when people tried to help you.

Thank you again

//+---------------------Thank you again---------------------------------------------+
//|          Abstract Class For Design Strategy                      |
//+------------------------------------------------------------------+
class CStrategy 
  {
private:

public:

   virtual double              Factory()                             { return 0;                }
   virtual datetime            GetTime()                             { return 0;                }
   virtual int                 GetMajick()                           { return 0;                }

  };
//+------------------------------------------------------------------+
//|                          CFirstPullBack                          |
//+------------------------------------------------------------------+
class CFirstPullBack : public CStrategy
  {


private:

   CCondition*       period;
   COHLC             _OHLC;
   double            _price;
   datetime          _time;
   int               _majicknumber;
   bool              Strategy(void);

public:

                     CFirstPullBack(CCondition* _period, int majicknumber):
                     period(_period),
                     _majicknumber(majicknumber) {}
   void              SetPrice();
   double            GetPrice(void)                                  { return _price;          }
   //--- Abs func
   double            Factory(void);
   datetime          GetTime(void)                                   { return _time;           }
   int               GetMajick(void)                                 { return _majicknumber;   }
  };

//main
/////////////////////////////////
CCondition M1(PERIOD_M1);
CCondition M5(PERIOD_M5);
CCondition M15(PERIOD_M15);

///////////////////////////////////

CFirstPullBack     FirstPullBack_M1(&M1, 111111);
CFirstPullBack     FirstPullBack_M5(&M5, 111555);
CFirstPullBack     FirstPullBack_M15(&M15, 151515);
Reason: