Semicolon after constructor body in documentation

 

Is this a typo or does this make some sense?

https://www.mql5.com/en/docs/basis/types/classes#initialization_list

class CPerson
  {
   string            m_first_name;     // First name 
   string            m_second_name;    // Second name
public:
   //--- An empty default constructor
                     CPerson() {Print(__FUNCTION__);};
   //--- A parametric constructor
                     CPerson(string full_name);
   //--- A constructor with an initialization list
                     CPerson(string surname,string name): m_second_name(surname), m_first_name(name) {};
   void PrintName(){PrintFormat("Name=%s Surname=%s",m_first_name,m_second_name);};
  };
 
Vladislav Boyko:Is this a typo or does this make some sense?

Why would it be a "typo"?

It is in fact valid, and most importantly, correct!

 
Fernando Carreiro #:

It is in fact valid, and most importantly, correct!

The following code will also be valid and correct:

class CPerson
  {
public:
   CPerson() {Print(__FUNCTION__);};;;;;;;;;;
  };
Fernando Carreiro #:
Why would it be a "typo"?

Because, if I'm not mistaken, there is no need for a semicolon there.

When I see this, suspicions creep in that I don’t understand something. Perhaps it is strictly necessary there for something. The main question of the topic: "Do I understand correctly that there is no need for a semicolon there?"

 
Vladislav Boyko #: The following code will also be valid and correct: Because, if I'm not mistaken, there is no need for a semicolon there. When I see this, suspicions creep in that I don’t understand something. Perhaps it is strictly necessary there for something. The main question of the topic: "Do I understand correctly that there is no need for a semicolon there?"

There is a diference between valid and correct.

Taking into consideration that MQL's roots are in C/C+++, then for the following example ...

... this is correct ...

class CPerson {
   public:
      CPerson() { Print( __FUNCTION__ ); };
};

... and this is valid ...

class CPerson {
   public:
      CPerson() { Print( __FUNCTION__ ); }
}
 

Here is another example of ...

... correct ...

if( condition ) {
   // do something
} else {
   // do something else
};

... valid ...

if( condition ) {
   // do something
} else {
   // do something else
}

... incorrect and invalid (in both cases below) ...

if( condition ) {
   // do something
}; else {
   // do something else
}
if( condition ) {
   // do something
}; else {
   // do something else
};
 

Here are the coding rules for the semicolon in C++, which probably applies to MQL as well.

C++ use semicolons to terminate a statement, since a statement is not required to fill up line. It can be shorter, it can be longer.

Semicolons are not required at the end of code-blocks (set of statements between {}) because “}” is itself a terminator.

So it is correct to terminate a statement with a semicolon, but it is not required after code blocks. Making it valid not to use them in such a case, but still technically correct to use them, since they terminate the statement.

 
Fernando Carreiro #:

Here are the coding rules for the semicolon in C++, which probably applies to MQL as well.

So it is correct to terminate a statement with a semicolon, but it is not required after code blocks. Making it valid not to use them in such a case, but still technically correct to use them, since they terminate the statement.

I got it, thank you very much!

 
class CPerson
  {
  ulong                 gender_id;
   string            m_first_name;     // First name 
   string            m_second_name;    // Second name
public:
   //--- An empty default constructor
                     CPerson() {Print(__FUNCTION__);};
   //--- A parametric constructor
                     CPerson(string full_name);
   //--- A constructor with an initialization list
                     CPerson(string surname,string name): m_second_name(surname), m_first_name(name) {};
   void PrintName(){PrintFormat("Name=%s Surname=%s",m_first_name,m_second_name);};
  };

I updated it for 2023  😅😅😅