Vague Parameters in a Class Constructor

 

Hi, 

Take a look at the class definition please:

class CExpertSignal : public CExpertBase
  {
protected:
   //--- variables
   double            m_base_price;     // base price for detection of level of entering (and/or exit?)
   //--- variables for working with additional filters
   CArrayObj         m_filters;        // array of additional filters (maximum number of fileter is 64)
   //--- Adjusted parameters
   double            m_weight;         // "weight" of a signal in a combined filter
   int               m_patterns_usage; // bit mask of  using of the market models of signals
   int               m_general;        // index of the "main" signal (-1 - no)
   long              m_ignore;         // bit mask of "ignoring" the additional filter
   long              m_invert;         // bit mask of "inverting" the additional filter
   int               m_threshold_open; // threshold value for opening
   int               m_threshold_close;// threshold level for closing
   double            m_price_level;    // level of placing a pending orders relatively to the base price
   double            m_stop_level;     // level of placing of the "stop loss" order relatively to the open price
   double            m_take_level;     // level of placing of the "take profit" order relatively to the open price
   int               m_expiration;     // time of expiration of a pending order in bars
   double            m_direction;      // weighted direction

public:
   ...
  };

And in the constructor:

CExpertSignal::CExpertSignal(void) : m_base_price(0.0),
                                     m_general(-1),          // no "main" signal
                                     m_weight(1.0),
                                     m_patterns_usage(-1),   // all models are used                                    
                                     m_expiration(0),
                                     m_direction(EMPTY_VALUE)
  {
  }


What are these parameters with this values inside parenthesis?  and What means ":" after the method's definition? 
Thank you!

Cheers,
Zarik


 
Zarik: Take a look at the class definition please: And in the constructor: What are these parameters with this values inside parenthesis?  and What means ":" after the method's definition?

I suggest you first take the time to read the documentation and to do some research into how to program in OOP (object oriented programming).

You will find a lot of research material on the web related to C++ OOP which is almost the same as MQL OOP.

 
Fernando Carreiro #:

I suggest you first take the time to read the documentation and to do some research into how to program in OOP (object oriented programming).

You will find a lot of research material on the web related to C++ OOP which is almost the same as MQL OOP.


Hez Fernando,

Thank you for your reply. I am constantly doing so, checking the documentation and online articles, but sometimes its like finding a Needle in a Haystack! Would you please point me more specifically to the part of the documentation where I can learn more about my questions? Really appreciate any small advices. 


Cheers,
Zarik

 
Zarik #: Thank you for your reply. I am constantly doing so, checking the documentation and online articles, but sometimes its like finding a Needle in a Haystack! Would you please point me more specifically to the part of the documentation where I can learn more about my questions? Really appreciate any small advices. 
CExpertSignal::CExpertSignal(void) : m_base_price(0.0),
                                     m_general(-1),          // no "main" signal
                                     m_weight(1.0),
                                     m_patterns_usage(-1),   // all models are used                                    
                                     m_expiration(0),
                                     m_direction(EMPTY_VALUE)
  {
  }

The highlighted sections are simply the calling of default constructors to initialise the member variables.

You should read the documentation from start to finish as if reading a novel. The reason is not to memorise everything but to serve as an overview, an outline, so that you can later more easily reference it when you require more details.

EDIT: Please note that not all the specifics of OOP can be found in the MQL documentation. Plenty of it is not described, but since MQL is very similar to C++, you will find more details of C++ OOP at other sources found on the web.

 

Documentation on MQL5: Language Basics / Data Types / Structures, Classes and Interfaces

...

There is a special syntax to initialize an object using a constructor. Constructor initializers (special constructions for initialization) for the members of a struct or class can be specified in the initialization list.

An initialization list is a list of initializers separated by commas, which comes after the colon after the list of parameters of a constructor and precedes the body (goes before an opening brace). There are several requirements:

  • Initialization lists can be used only in constructors;
  • Parent members cannot be initialized in the initialization list;
  • The initialization list must be followed by a definition (implementation) of a function.

Here is an example of several constructors for initializing class members.

//+------------------------------------------------------------------+
//| A class for storing the name of a character                      |
//+------------------------------------------------------------------+
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);};
  };
 
Fernando Carreiro #:

Documentation on MQL5: Language Basics / Data Types / Structures, Classes and Interfaces

...

There is a special syntax to initialize an object using a constructor. Constructor initializers (special constructions for initialization) for the members of a struct or class can be specified in the initialization list.

An initialization list is a list of initializers separated by commas, which comes after the colon after the list of parameters of a constructor and precedes the body (goes before an opening brace). There are several requirements:

  • Initialization lists can be used only in constructors;
  • Parent members cannot be initialized in the initialization list;
  • The initialization list must be followed by a definition (implementation) of a function.

Here is an example of several constructors for initializing class members.

You pointed me to the answer, no just the topic! Thank you very much! 🙏

Zarik

 
Zarik #: You pointed me to the answer, no just the topic! Thank you very much! 🙏
You are welcome!
Reason: