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!
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).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.