When the fictitious functions of the derived class and the base class have different real parameters by default;
The arguments of a derived class receive the default parameters passed by the base class.
The columns are as follows:
[Cpp]
# Include <iostream>
# Include <ostream>
# Include <string>
Using namespace std;
Class B {
Public:
Virtual void fun (int num = 0)
{
Cout <"B =" <num <endl;
}
};
Class D: public B {
Public:
Virtual void fun (int num = 1)
{
Cout <"D =" <num <endl;
}
};
Int main ()
{
D;
B * p = & d;
P-> fun ();
B & B = d;
B. fun ();
Return 0;
}
# Include <iostream>
# Include <ostream>
# Include <string>
Using namespace std;
Class B {
Public:
Virtual void fun (int num = 0)
{
Cout <"B =" <num <endl;
}
};
Class D: public B {
Public:
Virtual void fun (int num = 1)
{
Cout <"D =" <num <endl;
}
};
Int main ()
{
D;
B * p = & d;
P-> fun ();
B & B = d;
B. fun ();
Return 0;
}
The running result is as follows:
D = 0
D = 0