Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? The source code library is at your service!
Jordi Bassaganas
3525
Jordi Bassaganas 2013.07.03 11:02 

Hello there,

Today I am cleaning some OOP code written in MQL5 syntax! Right now I am pretty sure that you can write something like the following in compiled languages such as Java and C:

class CGraphic
   {
      public:
         string pair;
         CSymbolInfo symbol;
         ENUM_TIMEFRAMES timeframe;
         bar bars[];
      
         CGraphic(string pair)
         {
            this.pair = pair;
         }  
      
         // ...
         
         void SetPair(string pair)
         {
            this.pair = pair;
         }   
      
  };

In Java and C++ you can use the same name for referring both a parameter and a class property. There's no problem while you refer to the class property with the use of the word this, the compiler will be able to differentiate these two things! However, when I write the MQL5 counterpart I get this notice: "declaration of pair hides member declaration at line <number of the wrong line>".

How can I fix that? I am writing the following code to fix that notice but I find it is a bit redundant!. Is the following correct? Note that I preceed the name of the param with the prefix param_.

class CGraphic
   {
      public:
         string pair;
         CSymbolInfo symbol;
         ENUM_TIMEFRAMES timeframe;
         bar bars[];
      
         CGraphic(string param_pair)
         {
            this.pair = param_pair;
         }  
      
         // ...
         
         void SetPair(string param_pair)
         {
            this.pair = param_pair;
         }   
      
  };



Alain Verleyen
Moderator
30295
Alain Verleyen 2013.07.03 12:08  
laplacianlab:

Hello there,

Today I am cleaning some OOP code written in MQL5 syntax! Right now I am pretty sure that you can write something like the following in compiled languages such as Java and C:

In Java and C++ you can use the same name for referring both a parameter and a class property. There's no problem while you refer to the class property with the use of the word this, the compiler will be able to differentiate these two things! However, when I write the MQL5 counterpart I get this notice: "declaration of pair hides member declaration at line <number of the wrong line>".

How can I fix that? I am writing the following code to fix that notice but I find it is a bit redundant!. Is the following correct? Note that I preceed the name of the param with the prefix param_.

This is not an error this is a warning. Looking for problems where there are none, if you don't want warnings use different names.
Jordi Bassaganas
3525
Jordi Bassaganas 2013.07.03 12:19  
angevoyageur:
This is not an error this is a warning. Looking for problems where there are none, if you don't want warnings use different names.

Who talked about errors or warnings? Please, note that I said notice! Indeed nobody talked about the error you've noted.

I'm happy to know that I can use different names, so I'll keep on my improvement course...

Thanks for your reply!

Alain Verleyen
Moderator
30295
Alain Verleyen 2013.07.03 12:35  
laplacianlab:

Who talked about errors or warnings? Please, note that I said notice! Indeed nobody talked about the error you've noted.

I'm happy to know that I can use different names, so I'll keep on my improvement course...

Thanks for your reply!

I meant that it was not serious. You can also keep the same names and the warnings.

Personally I like to use some convention for function parameter, I add a prefix '_'

         CGraphic(string _pair) {...}



Jordi Bassaganas
3525
Jordi Bassaganas 2013.07.03 12:38  
laplacianlab:

Who talked about errors or warnings? Please, note that I said notice! Indeed nobody talked about the error you've noted.

I'm happy to know that I can use different names, so I'll keep on my improvement course...

Thanks for your reply!

This topic is interesting. I share the link below about warnings!:

https://www.mql5.com/en/docs/constants/errorswarnings/warningscompile

The manual says those messages are informative but some of them are a bit scaring, let me say. I don't know to what extent some of those notices may cause bugs I mean imprebisible consequences. 

Thank you again.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compiler Warnings
Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compiler Warnings
  • www.mql5.com
Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compiler Warnings - Documentation on MQL5
Jordi Bassaganas
3525
Jordi Bassaganas 2013.07.03 12:52  
angevoyageur:

I meant that it was not serious. You can also keep the same names and the warnings.

Personally I like to use some convention for function parameter, I add a prefix '_'



Thank you angevoyageur, I know that I am sometimes a bit boring or perfeccionist.

I take note about your convention for naming params. However I think that if all we follow our personal conventions it may lead to confusion!

That's why I opened the following thread:

About conventions in OOP MQL5 programs

Maybe it is a good idea to add the prefix '_'  for function parameters! I am going to see if there are many people doing this and if so I adhere.

/
To add comments, please log in or register