Errors, bugs, questions - page 1696

 
Stanislav Korotky:

Firstly, it's not clear whether or not an attempt was made to declare the method as virtual. If it has to be virtual, then write virtual in base class, not in derived class (because otherwise base pointers will be ripped to base method even if you put derived class instance into it).

If you don't want to override a method in a derived class, don't mention it at all, and if you do, it should be overridden with a body.

Finally, to hide the method from the derived class, you need to introduce an intermediate class where you move the method to the priivate area or make it private in the base class (but then why is it virtual?).

Here is an example

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class roditel
  {
public:

   virtual int one(void)
     {
      return 1;
     }
   virtual int two(void)
     {
      return 2;
     }
   virtual int three(void)
     {
      return 3;
     }
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class naslednic_1 : public roditel
  {
public:
   virtual int       two(void);
   virtual int       three(void);
  };

naslednic_1 go;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   go.two();
// 'two' - function must have a body    TEst.mq4        42      7
  }
//+------------------------------------------------------------------+
 
Vladimir Pastushak:

Here's an example

This example is about the same as the first ;-). You opened my letter but have not read it? What do you want to achieve by declaring the methods afresh in the descendant but not defining them? To call the basic implementation without having a new one, you don't need to mention them in the descendant.
 
Stanislav Korotky:
This example is about the same as the first ;-). My letter was opened, but you didn't read it? What do you want to achieve by redeclaring the methods in the descendant, but not defining them? To call a basic implementation without having a new one, you don't need to declare them in the descendant.

I want to see only 10 inherited methods plus methods created in descendant class. I don't need 190 methods, that won't be related to current class in any way.

For example, I have a base class where all maximum properties of shapes, width, height, corners, radii, colours, area are described.

Based on these property methods, I make a circle derived class that uses methods of parent class, radius, colour, area... But I don't need corners and width here ...

Based on these methods, I make a descendant triangle class that uses methods from parent class, colour, area, corners... But I don't need radius here ...

When I ask why, the parent class has a group of methods that are common to all or common to a group of shapes, like colour, style method.

 
Vladimir Pastushak:

I want to see only 10 inherited methods plus methods created in descendant class. I don't need 190 methods, that won't be related to current class in any way.

For example, I have a base class where all maximum properties of shapes, width, height, corners, radii, colours, area are described.

Based on these property methods, I make a circle derived class that uses methods of parent class, radius, colour, area... But I don't need corners and width here ...

Based on these methods, I make a descendant triangle class that uses methods from parent class, colour, area, corners... But I don't need radius here ...

When I asked why, parent class has a group of methods that is common to all or common to a group of shapes, e.g. method colour, style.

I do not understand: this question - a question or an underwritten answer? Usually they do so - in the base class it is common, and then in descendants they add particulars. Why do it vice versa? What is the purpose?

But even if you don't go deeper, I have already suggested an option - to insert an intermediate descendant in which all unnecessary properties and methods are moved to the private part.

 
Question to the administration, when will it be possible to see the new up-to-date statistics for the services?
 
Vladimir Pastushak:

There are 200 methods in the parent class, I want to see only 10 inherited methods plus the ones created in the child class, I don't need 190 more methods that are not related to the current class.

To do this, you need to declare inheritance as protected or private. And then override the methods you need.

class naslednic_1 : protected roditel
  {
public:
   virtual int       two(void)   { return roditel::two(); }
   virtual int       three(void) { return roditel::three(); }
  };
 
Alexey Navoykov:

To do this, you need to declare inheritance as protected or private. And then override the methods you want.

Stanislav Korotky:

I don't understand: is this question a question or an incomplete answer? Usually they do it this way - in a base class the general, and then in descendants they add particulars. Why do the opposite? What is the purpose?

But even if you don't go too deep, I have already suggested an option - to insert an intermediate descendant in which all unnecessary properties and methods are moved to the private part.

Thank you.

Alexey, your example doesn't work, in any case, the child gets parent methods, which should not get dumped.


 
How do I know myINDICATOR_SHORTNAME? IndicatorGet*-functions are missing!
 
Alexey Kozitsyn:
What if you change the short name when you create it?

And change every time?

If the indicator contains indicator buffers, self-identification is easy, but without buffers, I don't see a solution yet.

 
fxsaber:
How do I know myINDICATOR_SHORTNAME? IndicatorGet*-functions do not exist!
Print(MQLInfoString(MQL_PROGRAM_NAME)); returns the indicator short name. If no short name is specified - the full name is returned.
Reason: