Invalid Pointer Access error when one class has members that are instances of another class

 

I have a class library file that contains classes used in the main body of an MT4 EA (MetaEditor 5.00 build 2375). Here I have two classes:

The first one {#PivotPoint} has members for index and price of a pivot point.

The second class {#ForkDef} holds the parameters of a fork, most of which are instances of the #PivotPoint class.

So the code below can be compiled but when started in the MT4 client it gives error: "invalid pointer access" on line 56 {I have marked that line with an easy to see comment just above it}.

class PivotPoint
{
    public:
        int Index;
        double PP;
    
    public:
        // Default constructor
        PivotPoint(void){  //Print("Constructor initiated!");  
            };
        // Parametric constructor
        PivotPoint(int index, double pp)
        {
            Index = index;
            PP = pp;
            //Print("Parametric constructor initiated!");
        };
        
        // Default destructor
        ~PivotPoint(void){  //Print("Destructor executed!");  
            };
};


class ForkDef
{
    public:
        double step;
        PivotPoint *PP0;
        PivotPoint *PP1;
        PivotPoint *PP2;
        // midpoint between PP1 & PP2
        PivotPoint *ML;
        // PP1 WL line
        PivotPoint *WL1;
        // PP2 WL line
        PivotPoint *WL2;
    
    public:
        // Default constructor
        ForkDef(void){};
        // Parametric constructor
        ForkDef
            (
            double step_,
            PivotPoint &pp0, 
            PivotPoint &pp1, 
            PivotPoint &pp2, 
            PivotPoint &ml, 
            PivotPoint &wl1, 
            PivotPoint &wl2
            )
        {
            step = step_;
            // ----------------- the line below gives "invalid pointer access" error in MT4 client -------------
                        PP0 = pp0;
            PP1 = pp1;
            PP2 = pp2;
            ML = ml;
            WL1 = wl1;
            WL2 = wl2;
        };

        // copy constructor
        ForkDef(const ForkDef &fd)
        {
            step = fd.step;
            PP0 = fd.PP0;
            PP1 = fd.PP1;
            PP2 = fd.PP2;
            ML = fd.ML;
            WL1 = fd.WL1;
            WL2 = fd.WL2;
        };

        // Default destructor
        ~ForkDef(void){};
};

What am I doing wrong?

 
PP0 = GetPointer(pp0);
 
Ernst Van Der Merwe:

Thanks a lot! That worked!

:)))

Reason: