You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Maybe you can try
I declare a name as a class variable and want to assign its value at construction time. And due to my coding principle small is beautiful and smaller is even more beautiful I tried to use one command and defined the function as a 'global' function so that it is available to any class even if they do not exist yet - and that fails. :(
The best solution from my viewpoint still would be - as I tried and failed - typename(this).
I posted it at the service desk yesterday - it might take a while, if ..
My previous method works fine, and typename(this) works fine, too. For example:
But, if you want to create a generic function to get the type of any variable or structure or class, you can use a template like this. You would only have to pass your variable or structure or class instance to GetName function as a parameter:
Regards.
in MQL4this or any other pointer to an instance of a class like
creates an compiler error: '' - invalid cast operation.
BTW, the service desk answered: "Thanks for your suggestion, but we have no such plans."
in MQL4this or any other pointer to an instance of a class like
creates an compiler error: '' - invalid cast operation.
BTW, the service desk answered: "Thanks for your suggestion, but we have no such plans."
I don´t know what Service Desk said. The only thing I know is both of them are working fine in mql4 (Metatrader 4 build 1012, Metaeditor build 1395). Which is your MT4 build??- Did you test them??. You can test them, instead of asking Service Desk.
You have 2 EA examples attached. If your MT4 build isn't 1012, please don't recompile them. Regards-
An another ejample: MyClass3.mq4. Now storing m_name variable inside the constructor. Regards.
An another ejample: MyClass3.mq4. Now storing m_name variable inside the constructor. Regards.
Agree.
I don't understand the problem either. And by the way why do one want a class name inside a class ?
Agree.
I don't understand the problem either. And by the way why do one want a class name inside a class ?
I don't know. It's a question for Carl. He said that typename(this) doesn't work in mql4, and I proved it's working fine. Now, he have the solution (3 different solutions), and he will be able to use like he wants. Regards
I want to be able to use my OOP-code by a script, an EA and e.g. as the heart of an indicator. Due to the options of virtual methods and method overloading it can happen that - while developing - you 'land' in the wrong method or to be precise in the method with the same name but of the wrong (e.g. base-) class. In the debugger it is easy to detect, but at least in MQL4 you can't really debug an indicator, so you have to show it either by Print or Comment().
I don't know what has been a problem on my side and why I have got the compiler error (s.th. like "the conversion is not allowed") - it must have been my error - but now typename(this) works - thanks!