Download MetaTrader 5

is there a way to call base virtual function from descendant ?

To add comments, please log in or register
Iggy
478
Iggy  

is there a way to call base virtual function from descendant ? (eom)

sometimes virtual function from base class can define common action for descendant classes before or after specific action the descandant performs just like destructors go down the chain 

Alexey Da
Moderator
6648
Alexey Da  

Have you read this topic?

Could give us some example? 

Iggy
478
Iggy  
alexvd:

Have you read this topic?

Could give us some example? 

Actually I tried it and it does work... Here is an example.
class CHello
{
public:
        virtual string echo() { return("Hello "); }
};

class CWorld : CHello
{
public:
        virtual string echo() { return(CHello::echo() + "World "); }
};

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
        CWorld world;
        printf("%s",world.echo());
        
}

output:

2010.07.16 12:57:42 AccountInfo (EURUSD,M1) Hello World

in other words it allows to perform some common code for all the descendants in the base class 

 

Here you need to know the name of the base class to call it. In other languages there is a generic name for this like "base::echo" 

Alexey Da
Moderator
6648
Alexey Da  
irusoh1:
Actually I tried it and it does work... Here is an example.

output:

2010.07.16 12:57:42 AccountInfo (EURUSD,M1) Hello World

in other words it allows to perform some common code for all the descendants in the base class 

 

Here you need to know the name of the base class to call it. In other languages there is a generic name for this like "base::echo" 

It wont be realized.
Slava
Moderator
6918
Slava  
irusoh1:

Here you need to know the name of the base class to call it. In other languages there is a generic name for this like "base::echo" 

Of course. You need to know.
To add comments, please log in or register