#include <iostream>
class A
{
public:
virtual ~A() = default;
virtual int fun(int = 0, float = 5.4f) = 0;
};
class B: public A
{
public:
int fun(int i = 8, float k = 4.5f) override // You may change default values
// but not recommended
{
std::cout << "fun(i = " << i << ", k = " << k << ")\n";
return 0;
}
int fun(int i, float k, char c) // it is not an override
{
std::cout << "fun(i = " << i << ", k = " << k << ", c = "<< c << ")";
if(c != 'g') {
std::cout << " -> ";
return fun(i, k);
} else {
std::cout << std::endl;
return -1;
}
}
};
int main() {
B b;
A& a = b;
a.fun(); // fun(0, 5.4)
b.fun(); // fun(8, 4.5) // That part may surprise user
a.fun(-1, 10.5f); // fun(-1, 10.5f)
b.fun(42, 4.2f, 'g'); // fun(42, 4.2, g)
b.fun(420, 6.9f, 'f'); // fun(420, 6.9, f) -> fun(420, 6.9)
}