"access to non-static member or function" Error - page 2

 
Keith Watford:

You have misunderstood.

With an EA, static and global variables are not reinitialized when the EA is reinitialized. If the coder requires that they are reinitialized, it must be coded to do do.

probably!

 
Jonathan Pereira:

I consider it a bad practice to create a variable within OnInit

You have missed the point.

Williams example was just to show that static variables are not re-initialised when the EA is re-initialised.

Beside that why do you consider it bad practice to create local variables in OnInit?

I do it all the time.

ie temporary string arrays when using StringSplit() that is then converted to a double/int to be stored in a globalscope array.

X and Y distances to increment when creating a list of labels with a loop.

As these variables are only used in OnInit, they must either be created in OnInit or declared globally. Now using a globalscope variable that will only be accessed in OnInit IS bad practice.

 
Keith Watford:

You have missed the point.

Williams example was just to show that static variables are not re-initialised when the EA is re-initialised.

Beside that why do you consider it bad practice to create local variables in OnInit?

I do it all the time.

ie temporary string arrays when using StringSplit() that is then converted to a double/int to be stored in a globalscope array.

X and Y distances to increment when creating a list of labels with a loop.

As these variables are only used in OnInit, they must either be created in OnInit or declared globally. Now using a globalscope variable that will only be accessed in OnInit IS bad practice.

Every development I do is external to the EA code, so I only include the modules as needed.

Obviously when there is a need for data manipulation in OnTick, OnInit and any other handler, I make them public members of my modules. Therefore, the declaration of these variables is in their respective namespace. Anyway, there is no standard of good practice in MQL5, but common sense.

As a developer I find the habit of leaving variables "loose" in the code terrible.

 
I have this same problem, solution in my case was missing semicolon, and it happens 2 times. I take long time to figure out where I make mistake. And after I found it, all problems was gone.
Reason: