1.练习代码
#include "stdafx.h"
#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 _tmain(int argc, _TCHAR* argv[])
{
base obj(98);
cout << obj.get_i() << endl;
cout << obj.get_j() << endl;
return 0;
}
2.关键点分析
2.1执行过程
#include "stdafx.h"
#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 _tmain(int argc, _TCHAR* argv[])
{
base obj(98);
cout << obj.get_i() << endl;
cout << obj.get_j() << endl;
return 0;
}
2.2运行结果
