Problem Creating Class Objects

Back to topics list To post a new topic, please log in or register
avatar
4
tymoore510 2015.03.25 17:12
 
I am trying to create objects of a class that have a global scope. However when I try to assign the instances of the class to the variables (the pf array), I am receiving an error "'=' - object required". What am I doing wrong?
//+------------------------------------------------------------------+
//| Classes                                                          |
//+------------------------------------------------------------------+
class SampleClass
{
public:
   // Variables
   int Length;
   double ds[];
   
   // Constructors   
   SampleClass(void){};
   SampleClass(int length, int bufferNum)
   {
      Length=length;
      SetIndexBuffer(bufferNum,ds);
   };      
      
   void Calculate()
   {
      int bar = Bars-IndicatorCounted();
      if (bar<Length)      
         return;  
         
         double var0, var1;
         double sum = 0, sumif = 0;   
         for (int x=0;x<Length;x++)
         {
            double p1 = Close[x];
            double p2 = Close[x+1];
            
            sum+=p1*p1;
            if (p1>p2)
               sumif+=p1*p2;
         }
         
         var0=sumif;
         var1=sum;
         
         if (var1!=0)
            ds[bar]=100*var0/var1;
         else
            ds[bar]=0;
   };
};

SampleClass pf[3];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,indBuffer);
   
   pf[0] = new SampleClass(9,1);
   pf[1] = new SampleClass(19,2);
   pf[2] = new SampleClass(33,3);

//----
   return(0);
  }

avatar
1109
Ovo 2015.03.25 18:09 #
 
tymoore510:
I am trying to create objects of a class that have a global scope. However when I try to assign the instances of the class to the variables (the pf array), I am receiving an error "'=' - object required". What am I doing wrong?

The new operator returns a descriptor (a "dynamic pointer" in their terminology), so the declaration must be SampleClass* pf[3];

In that case you do not need the default constructor either.

avatar
4
tymoore510 2015.03.26 16:43 #
 
Ovo:

The new operator returns a descriptor (a "dynamic pointer" in their terminology), so the declaration must be SampleClass* pf[3];

In that case you do not need the default constructor either.

That did the trick. Thank you very much for your assistance!
Back to topics list  

To add comments, please log in or register