Do not neglect the compiler's warnings
Compiler warnings don't bother some programmers. They believe that warnings do not threaten the program or do not have much of a side effect on the program. However, this idea may cost a great price when it comes to programming.
Here's an example:
class B{ public: virtualvoidfconst; }; public B{ public: virtualvoidf(); };
The programmer of this code wants class D to inherit the F () function of Class B, but it is not declared as const in D. The compiler will not make an error, and may give the following warning:
warningD::f()hidesvirtualB::f()
You might think that's what we want to do. But the compiler is trying to tell you that B::f is not re-declared in D, but is obscured. If you ignore this warning, such as causing error behavior. Polymorphism can be compromised at this time.
The following code:
#include <iostream>using namespace STD;classb{ Public:Virtual voidF ()Const{cout<<"Class B"<< Endl; };};classB | Publicb{ Public:Virtual voidF () {cout<<"Class D"<< Endl; };};intMain () {B *b; B B1; D D1; b = &b1; B->f ();//Call Class B's FD1.F ();//Call Class D's Fb = &d1; B->f ();//Call Class B's F return 0;}
Learn from compiler warnings that learning about warning messages is not the same as what they seem to mean. Programs that do not have any warnings at the highest warning level are ideal, but have a deep understanding of warning, and you can choose to ignore certain warning messages. But remember, before ignoring this warning, be sure to understand its true intentions.
Warning messages are related to the compiler, and different compilers have different warning standards. For example, the function in the above code obscures the compiler in another compiler, and there may be no warning.
Effective C + + clause 53