The default initialization order for class members is in the order of declaration, and if you initialize a member variable with an initialization list, you must follow the declaration order of the member variable;
Otherwise, when alternating between variables, an uninitialized variable is created to assign the other variable;
GCC also emits a warning, such as: ' Class::m_xxx ' will be initialized after [-wreorder]
Code:
* * * * * BInsertSort.cpp * * Created on:2014 April 15
* author:spike/
#include < iostream>
#include <string>
using namespace std;
Class Base {
private:
int m_i;
int m_j;
Public:
Base (int i): M_j (i), m_i (M_j) {}
base (): M_j (0), m_i (M_j) {}
int get_i () {return m_i;}
int Get_j () {return m_j;}
};
int main () {
base obj ();
Std::cout << obj.get_i () << Std::endl
<< obj.get_j () << Std::endl;
return 0;
}
Output:
4202398
98
Author: csdn Blog spike_king
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/