Hi experts,
I have a little bit confuse about class.Would someone please clarify this? Please see following code and its result,
The results show different despite both function are called from base class.Why not the same?
I understand that, If there is prefix “virtual” in front of the function , They must be used by child only?
Thank you so much
class CBase
{
public:
virtual string Function()
{
return("2 = Base");
}
string Function2()
{
return("2 = Base");
}
};
//+------------------------------------------------------------------+
//| Child class 1 |
//+------------------------------------------------------------------+
class Class1: public CBase
{
public:
string Function()
{
return("1 = Child");
}
};
//+------------------------------------------------------------------+
Class1 c1; // Load class 1
//+------------------------------------------------------------------+
//| Function to process objects |
//+------------------------------------------------------------------+
void Function(CBase &c)
{
Alert(c.Function());
}
void Function2(CBase &c)
{
Alert(c.Function2());
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart()
{
// Process objects using one function.
Function(c1);
Function2(c1);
}