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!
This is a discussion on Virtual Function and Its formal parameters within the C++ Programming forums, part of the General Programming Boards category; Hi, I was wondering if the formal parameters must remain the same in a class' virtual member function and that ...
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).
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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).
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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.
Arrogance breeds bad code