Can't you make the parameters of the constructor even more simple (untested - just an idea):
#include <Object.mqh> class CGlobalObject : public CObject { private: int m_index; protected: CGlobalObject(const double a_value=DBL_MAX); ... CGlobalObject::CGlobalObject(int a_value) { m_index = GlobalVariablesTotal(); if ( a_value==DBL_MAX ) {...} else {... } }
This way you can call the constructor - I think - either with or without a value and as it called only once for an object it wont crash the performance.
But why do you write : m_index(GlobalVariablesTotal()) ??
m_index is int not a function!
Can't you make the parameters of the constructor even more simple (untested - just an idea):
This way you can call the constructor - I think - either with or without a value and as it called only once for an object it wont crash the performance.
But why do you write : m_index(GlobalVariablesTotal()) ??
m_index is int not a function!
It is because I wanted to experiment with the OOP syntax and I saw this somewhere in standard library, I think it is called direct initialisation, but I haven't come to testing it yet.
When you think about the indizes of global variables, they are unique. Just realized I will have to build some logic for when they get deleted after a month.
I figured if I wanted to get the GlobalVariableName(int index) I would need the actual index of the global variables, then I can use GlobalVariableName(m_index) to call all the other functions...
Thanks for the contribution. Will give it a thought, although it would be nice to be able to use what I can learn from standard library. On second thought I will probably wind up using it, thanks!
It is because I wanted to experiment with the OOP syntax and I saw this somewhere in standard library, I think it is called direct initialisation, but I haven't come to testing it yet.
When you think about the indizes of global variables, they are unique. Just realized I will have to build some logic for when they get deleted after a month.
I figured if I wanted to get the GlobalVariableName(int index) I would need the actual index of the global variables, then I can use GlobalVariableName(m_index) to call all the other functions...
Thanks for the contribution. Will give it a thought, although it would be nice to be able to use what I can learn from standard library. On second thought I will probably wind up using it, thanks!
To save information constantly and available for other terminals I would use csv files in the Common folder.
It is so easy to read such a file into an array of all lines and then split a line into cells:
// read a csv file in an array of lines int getCsvLines( const string fName, string &l[], int flag=0, ushort sepLine='\n') { // alternative to FileOpen uchar Bytes[]; return( FileLoad(fName, Bytes, flag) ? StringSplit(CharArrayToString(Bytes), sepLine, l) : 0); } // and split each line into an array of cells: int getAllCells(const string line, string &cells[], ushort sepItm=';'){ int nI = StringSplit(line,sepItm,cells); // ushort SepItem = StringGetCharacter(";",0); return(nI); }
So somebody pm'd me and they said it should be like this:
CGlobalObject::CGlobalObject(double a_value) : m_index(GlobalVariablesTotal()) { GlobalVariableSet(ConcName(),a_value); }
That is what I overlooked. Then again the error message didn't make very much sense in that respect.
To save information constantly and available for other terminals I would use csv files in the Common folder.
It is so easy to read such a file into an array of all lines and then split a line into cells:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi.
I am working on wrapping Global Variables of Terminal in a class so I can use them like a simple variables array, just in abstract data type CGlobalObject. However... I don't get why the compiler doesn't seem to like me making different overloads of the class constructor method. I must be overlooking something, but it is like in a game of chess: The less pieces are left, the more difficult it seems not to overlook anything. Don't quote me on this one.
So. Compiler says: CGlobalObject - member function already defined with different parameters - How is it different from this below?
I know it won't compile. It is from Include/Math/matrix if you need the source.