In C++, a derived class's method only overrides the base class's method if their declarations match (I say "match," but I'm not sure what the formal term is).
That is, all arguments must be of the same type, with the same const qualification.
If there are any mismatches, the derived class's method hides all methods with the same name rather than overriding.
This is what the "ERROR" in your image is attempting to convey.
So, in that image, / overrides in a comment is incorrect and misleading.
Yes, many C++ instructors are unaware of these somewhat esoteric details.
Furthermore, if you want to override, your base class's method must be virtual; otherwise, polymorphism will not work.
. We could also say that the derived-class method hides the base-class method if it wasn't virtual.
The part about hiding, on the other hand, has almost no meaning here; what this term really means is that you're not in charge.
Furthermore, overloading is the presence of multiple methods with the same name but different signatures, as you may have noticed. To be useful, they must all be present in the derived class; otherwise, they will be hidden if the derived class only has one method, fa1, and the other fa1 are in the base. There is, however, a syntax sugar that "copies" all fa1 from base to derived, removing all the hidden semantics:
class A
{
public:
void fa1();
...READ MORE
Jun 7, 2022
in C++
by
Damon
• 4,960 points
•
802 views