class Mother
{
public:
int m_i;
Mother(const int & i_in = 0)
: m_i(i_in)
{
cout << "Mother construction" << "\n";
}
};
class Child : public Mother
{
public:
double m_d;
public:
Child()
: Mother(1024), m_d(1.0) //m_i(1) initialization list에서는 초기화 불가. 아직 mother 의 construction이 실행되기 전이기 때문. Mother()이 숨어있다. Mother에 constructor를 따로 구현해놓았을 경우 Mother(1024)와 같이 초기화 가능.
{
cout << "Child construction" << "\n";
//this->m_i = 10; 여기선 가능.
//this->Mother::m_i = 1024; mother의 멤버라는 것을 강조할 때는 이렇게도 쓸 수 있다.
}
};
int main()
{
Child c1; // Mother construction -> Child construction
return 0;
}