Errors, bugs, questions - page 1678

 
Комбинатор:
You can use this to make an analogue of the keyword final, explicitly prohibiting further inheritance.
But as the example above shows, you can't make an analog. You must specify final even for private-methods.
 
fxsaber:
But as the example above shows, you can't make an analogue. You must specify final even for private methods.

Strange. For public inheritance, the maximum access should be protected, not private.

And the function in the example is being overloaded exactly?

 
Комбинатор:

Strange. For public inheritance, the maximum access should be protected, not private.

And in the example, is the function exactly overloaded?

Right. I just found it out myself.

If you do in the example

BASE() {Func();} // вместо void Init() {Func();} Вызов  Base.Init() - убрать конечно.

you can check yourself after you run it and see if you know what's supposed to happen.

 

In the terminal log I get

2016.09.12 15:49:14.209 Simple_Test (RTS-9.16,M1)       array out of range in 'Simple_Test.mqh' (85,33)

clumsily go to the specified location in the source code. It would be convenient if you could double-click on such a message in the terminal log and get straight to the specified line.

If anyone supports it, speak up.

 
Sergei Vladimirov:

The classic is an interface in a base class with redefinition in descendants:

Classic is when protected/public-virtual methods are overridden. But for private, it's not so obvious (in terms of application). Thanks for the reply.
 
fxsaber:
Classic is when protected/public virtual methods are overridden. But for private, it's not so obvious (in terms of application). Thanks for replying.

Yes, I already deleted my example without seeing your reply, it was really unfortunate.

Upd. I got confused in the basics myself while I was answering you. Everything was correct in that example, I shouldn't have deleted it. The same example again with an example of use:

class CAnimal
{
private:
   void virtual Speak(){}
};

class CDog : public CAnimal
{
public:
   void Speak(){Print("Гав!");}
};

class CBigDog : public CDog
{
public:
   void Speak(){Print("Громкий гав!");}
};

void OnStart()
{
   CDog oDog;
   oDog.Speak();
   
   CBigDog oBigDog;
   oBigDog.Speak();
   
   CDog* pDog = &oBigDog; 
   pDog.Speak();       // "Громкий гав!", а не "Гав!", как было бы без виртуального метода
}
 
Sergei Vladimirov:

Upd. I got confused in the basics myself while I was answering you. Everything was correct in that example, I should not have deleted it. Again with an example of how to use it:

Not a good example, since we can't see the CAnimal interface being used anywhere. Yes, they also made two descendants public. I understand the topic, so it's ok.
 
#property indicator_buffers 1 + 1

The compiler does not make a deuce.

 
fxsaber:
This is not a good example, since we can't see the CAnimal interface being used anywhere. Also two descendants have been made public. I understand the topic, so it's ok.

Normal example. An abstract animal basically makes some sound, but undefined, so we cannot call the Speak() method on it; it can only be called on an animal of a specific species. Therefore we declare a closed virtual method in a base class, and override it in descendants and open it.

 
Sergei Vladimirov:

Normal example. An abstract animal basically makes some sound, but undefined, so we cannot call the Speak() method on it; it can only be called on an animal of a specific species. Therefore we declare a closed virtual method in a base class, and override it in descendants and open it.

It would be useful to make it private in descendant classes as well. For better understanding. Not the point, in short.
Reason: