Deprecated behavior, hidden method calling will be disabled in a future MQL compiler version - page 3

 
Petr Nosek #:

I'm sorry, but I don't think we understand each other. There is no problem with ambiguous code in the sample code. The problem is not with the Name(const string name) method that I declared in the derived class, but the problem is with the Name(void) method of the parent class, which is not declared in the derived class at all.

Yes, you are right, the compiler warning does refer to the line where Name(void) is called, which you did not redeclare.

#include <Trade\SymbolInfo.mqh>

class CSymInfo : public CSymbolInfo
  {
public:
   bool Name(const string name) { return(CSymbolInfo::Name(name));  }
  };

void OnStart()
  {
   CSymInfo symbolInfo;
   symbolInfo.Name(_Symbol); // OK
   string name = symbolInfo.Name(); // deprecated behavior, hidden method calling will be disabled in a future MQL compiler version
  }
 
Amir Yacoby #:

It's not my conclusion, a function with same name in inner scope as the one in outer scope - the inner one hides the outer one.

This is c++ and also MQL5.

The reason of the warning:



is that there is an ambigiuity in hiding (not overriding) which is implicitly allowed in current MQL5 version which will not be allowed in future versions.

You are forgetting about the scope. Its a scope issue, not a "hide" issue. - Commonly referred to as function shadowing. - This is not the case here.


 
Amir Yacoby #:
The problem is that CSymbolInfo has 2 Name() methods, one with parameters and one parameterless.

By redefining Name() in your derived class CSymInfo with a specific parameter ( const string name ), you've hidden the parameterless version of Name() from the base class. This is what triggers the compiler warning.
You seem to be mixing override with overload.

Override is across scope boundaries, while overload is in the same scope.

If you overload across scope, you get the warning.
 
Dominik Egert #:
You seem to be mixing override with overload.

Override is across scope boundaries, while overload is in the same scope.

If you overload across scope, you get the warning.

Well if you read the thread carefully you'll see that that was my point all the way 

But the problem here is with what you call shadowing or hiding of the methods
 
Dominik Egert #:
If you overload across scope, you get the warning.

There is no overload across scope as you know. When you do that, and the base is not virtual, than it's called hiding.

 
Amir Yacoby #:

Well if you read the thread carefully you'll see that that was my point all the way 

But the problem here is with what you call shadowing or hiding of the methods

Then this post has made me misunderstanding what you are trying to say:

https://www.mql5.com/en/forum/479024#comment_55528034

Edit: no, it has nothing to do with hiding/shadowing. Its a scope issue.
 

Because one post prior to that there was another question asked which I was referring

 
Dominik Egert #:

Then this post has made me misunderstanding what you are trying to say:


Edit: no, it has nothing to do with hiding/shadowing. Its a scope issue.

The message itself is saying that it is about hiding.. read the message

Edit: right, and hiding happens across scope when there is no override (because for instance the base method is not virtual). 
 
Dominik Egert #:

This should give clarity in some sense:

Thanks for the link. So far I haven't really understood how it relates to my question, but I'll keep trying :-)

Just to be sure, I'll repeat my conclusion and I'll be glad for confirmation, or for a demonstration of how this problem can be bypassed.

If there are 10 overloaded methods in the parent class and I want to override the behavior of only one of them in the derived class, I still have to declare all 10 in the derived class.

 
Amir Yacoby #:

The message itself is saying that it is about hiding.. read the message

Edit: right, and hiding happens across scope when there is no override (because for instance the base method is not virtual). 

So, here is a real world "sample-code", that will give you a full usage of all working versions of overloading, overriding and inheritance that MQL5 supports. - MQL5 is limited in its inheritance, as it does not support merging.


I guess, you will need a while to figure this out.


#include <test.mqh>

void Start()
{
        tree<MqlRates> my_datastore;
}


EDIT: The uploaded file as a typo in line 662: it should have been const, not cosnt...

Files:
test.mqh  155 kb