Hi,
I was wondering if the formal parameters must remain the same in a class' virtual member function and that of its derived class? Thanks!
Printable View
Hi,
I was wondering if the formal parameters must remain the same in a class' virtual member function and that of its derived class? Thanks!
Yes (though you can change or omit their names if you want).
In this example:
So B: f(int a, float b, double c, char* d) is not correct, but B:f(int b, float , double c) is?Code:class A{
virtual f(int a, float b, double c)
}
class B: public A{
...
}
Yes, at least if your intention is to override the virtual function instead of overload with another member function named f (and this overload would cause the inherited f to be hidden).
Thanks!
So this is overload
and this is overrideCode:class A{
virtual f(int a, float b, double c)
}
class B: public A{
f(int a, float b, double c, char* d) // overload A::f
}
Code:class A{
virtual f(int a, float b, double c)
}
class B: public A{
f(int b, float , double c) // override A::f
}
You need to specify return types too.
Oops.
Thank you!
And now for the real question. Why do you think this is the case? The answer will show whether or not you understand what is going on. Just knowing the answer is not good enough. You must understand why.