PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page
1 #include <iostream.h>
2
3 class Animal
4 { public:
5 virtual char *speak(int) { return "silence"; }
6 };
7
8 class Cat : public Animal
9 { public: char *speak(int) { return "meow"; } };
10
11 class Dog : public Animal
12 { public: char *speak(short) { return "bow-wow"; } };
13
14 int main()
15 { Animal *p = new Dog; cout << p->speak(0); return 0; }
The speech of dogs is supposed to be 'bow-wow' but instead the program prints 'silence'. Why did the dog not bark? Do not be misled by the famous Sherlock Holmes mystery where the dog that did not bark was a 'friend' of the criminal. No reflection on our major media is intended either.
--- Module: bug1411.cpp
_
{ public: char *speak( short ) { return "bow-wow"; } };
bug1411.cpp(12) : Warning 1411: Member with different signature
hides virtual member Animal::speak(int) (line 5)
_
{ Animal *p = new Dog; cout << p->speak( 0 ); return 0; }
bug1411.cpp(15) : Warning 613: Possible use of null pointer (p) in
left argument to operator '->'
bug1411.cpp(15) : Warning 429: Custodial pointer 'p' (line 15) has
not been freed or returned
--- Wrap-up for Module: bug1411.cpp
Info 753: local class Cat (line 8, file bug1411.cpp) not referenced
1411 Member with different signature hides virtual member Symbol
(Location) -- A member function has the same name as a virtual
member of a derived class but it has a different signature
(different parameter list). This is legal but suspicious,
because it looks as though the function would override the
virtual function but doesn't. You should either adjust the
parameters of the member so that the signatures conform or choose
a different name. See also message 1511.
Previous Bug - Bug #661 - February 1998
Next Bug - Bug #794 - April 1998