While I was sleeping?

 

When did the '*' that marks that a method returns an object pointer became redundant in MQL5?
It also seems the same with structs and '&'

class MyClsB
{
};
class MyClsA
{
   MyClsB Check(); // This was not compiled once without '*'
};
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---

  }
 
Amir Yacoby: When did the '*' that marks that a method returns an object pointer became redundant in MQL5?

It also seems the same with structs and '&'

  1. Not redundant. You have to declare the variable as a pointer. It is the use of that pointer that does not require an asterisk (unlike C/C++).

  2. Your posted code isn't using pointers.

  3. What can be returned: simple types, simple structures, object pointers. With the return operator you can't return any arrays, class objects, variables of compound structure type.

              Return Operator - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Unfortunately the documentation is outdated in a lot of places.

And there are even places where there are documentation for stuff which are not yet implemented.

 
Alain Verleyen #:

Unfortunately the documentation is outdated in a lot of places.

And there are even places where there are documentation for stuff which are not yet implemented.

Yes it seems a preperation for something. 
William I know it doesn't use pointers, it's intended. It compiles which is different from previous versions. 
 
Amir Yacoby #:
Yes it seems a preperation for something. 
William I know it doesn't use pointers, it's intended. It compiles which is different from previous versions. 

I asked Metaquotes to fix this documentation (link from William). I don't know since when it's possible, but it's certainly not a recent change.

Though I never use it as it implies a copy, which is not efficient at all. What could be a good usage ?

 
Alain Verleyen #:

I asked Metaquotes to fix this documentation (link from William). I don't know since when it's possible, but it's certainly not a recent change.

Though I never use it as it implies a copy, which is not efficient at all. What could be a good usage ?

Well, yes you seem to be right. It is returning the object by value, which is copying it using the copy constructor.

I didn't know that you can return an object by value like that, I am almost sure it wouldn't compile in previous (maybe not recent) versions.

class MyClsA
  {
private:
   int               m_size;
public:
   MyClsA(const MyClsA &other)  // copy constructor
      {
         this.m_size=other.m_size;
      }
   MyClsA            Max(const MyClsA &a,const MyClsA &b)
     {
      if(a.m_size>b.m_size)
         return a;      //--- calls copy constructor
      else
         return b;      // calls copy constructor
     }
  };
 
Comments that do not relate to this topic, have been moved to "Off Topic Posts".
Reason: