Compilation errors when using -> for methods on pointers in MQL5
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
I get compilation errors in MQL5 when trying to use methods on pointers via the -> operator (e.g. ptr->SayHello()).
Errors: '>' - operand expected, 'SayHello' - undeclared identifier and others.
MetaEditor build 4873 (February 2025) is used, file .mq5, code is entered manually without typos.
The MQL5 documentation (section 'Object Pointers') states that in MQL5, as in C++, pointers to objects are created via `new`.
In C++, the `->` operator is used to call methods of dynamically created objects. It would seem to work, but it does not compile.
There is no explicit indication in the docs that this method call option is not supported in MQL5. Can anyone explain?
Example code for testing:
class MyClass { public: void SayHello() { Print("Привет от указателя!"); } }; void OnStart() { MyClass* ptr = new MyClass(); ptr.SayHello(); // Здесь возникают ошибки delete ptr; }
- www.mql5.com
I get compilation errors in MQL5 when trying to use methods on pointers via the -> operator (e.g. ptr->SayHello()).
Errors: '>' - operand expected, 'SayHello' - undeclared identifier and others.
MetaEditor build 4873 (February 2025) is used, file .mq5, code is entered manually without typos.
The MQL5 documentation (section 'Object Pointers') states that in MQL5, as in C++, pointers to objects are created via `new`.
In C++, the `->` operator is used to call methods of dynamically created objects. It would seem to work, but it does not compile.
There is no explicit indication in the docs that this method call option is not supported in MQL5. Can anyone explain?
Example code for testing: