1 # warning:... will be initialized after.../... warning: When initialized here [1] [2]
Example:
Class Foo {// declaration int I; Int J; public: // constructor & Its initializer Foo (INT Val): J (VAL), I (j ){}};
In this example, the above warning message is displayed when the foo class is compiled.
C ++ rules: In the constructor's initializer list, the actual sequence of the compiler to initialize the members is determined by the Declaration/definition sequence of the members, it is irrelevant to the sorting order of the members in the initialization list. In this example, the declared order is first I and then J. According to this rule, the compiler will also initialize I and then J. The above example is as follows:
Foo (INT Val): J (VAL), I (j ){}
In the compilation process, the first step is to use a member J that has not been initialized to initialize Member I. Program Brings bugs. Therefore, the compiler provides the preceding warning message in a friendly manner. The solution is to adjust the initialization sequence, which is consistent with the declared sequence:
Foo (INT Val): I (VAL), J (VAL ){}
Ref.: [1] C ++ primer (Chinese Version 4th); article 9 [2]
Stackoverflow.com
2 # Waring: Virtual... Was hidden... [3] [4] [5] example:
Class base {public: Virtual int FCN () ;}; class derive: public base {public: // for clearing the warning, uncomment: // using base: FCN; // However, it's not a good idea to do this (using Declaration) If this codes are in any header file. // or, uncomment: // int FCN (); int FCN (INT) ;}; int main () {STD: cout <"Yeah \ n "; return 0 ;}
During compilation, if the warning option-woverloaded-virtual is added to G ++ or makefile, the above warning message is displayed. Example: $ g ++ overloadbasemember. CC-woverloaded-virtual
Overloadbasemember. CC: 33: Warning: 'virtual int base: FCN () 'was hidden
Overloadbasemember. cc: 43: Warning: By 'int derive1: FCN (INT) 'This is because after the derived class derive inherits the base class, the FCN function of the base class is overloaded in the class scope, so the FCN () function of the original base class will be blocked/invisible in this scope. The solution is to use the using Declaration (using Declaration) in the derived class to re-declare all functions named FCN in the base class (9 rows) so that they can be seen. However, this method is not recommended in header files. Another method is to directly redefine the FCN () function (12 rows) in the base class in the derived class derive ). Of course, you can simply remove the-woverloaded-virtual option to ignore such warnings. What are the risks of doing so, and why should C ++ reserve such warnings? Sorry, I have not figured it out yet. It will be available soon. Article Update before understanding. (Hope you can give me some advice) Ref.: [3] C ++ primer Chinese Version 4th P501 [4]
Stackoverflow.com [5]
When the heart virtual function overload (overloaded-virtual) by Jin Qing
3 # warning: statement has no effect Example:
Int I = 0, n = 100; for (I; I <n; I ++ ){}
Correct example:
Int I = 0, n = 100; for (; I <n; I ++ ){}
// Orfor (I = 0; I <n; I ++ ){}
Either do something (definition, initialization/value assignment) for the first parameter of the For Loop, or leave the first parameter empty. Otherwise, a 3 # warning message is displayed.