강의

멘토링

커뮤니티

Inflearn Community Q&A

thd2tn1756's profile image
thd2tn1756

asked

Following and Learning C++ with Hong Jeong-mo

8.4 Constructor member initialization list

7:45 부근 질문있습니다.

Resolved

Written on

·

172

0

B m_b는 Something과는 다른 class이고 instance 멤버가 private인데 어떻게 class Something에서 B m_b { 1024 }와 같이 초기화가 가능한지 궁금합니다.

C++

Answer 1

1

우선 private으로 선언된 것은 크게 상관이 없습니다.

그리고 다른 클래스를 인스턴스 멤버로 얼마든 초기화할 수 있습니다.

아래 코드를 보세요 (강의에서 제시해주신 코드입니다)

이를 통해 초기화됩니다.

 

public:
    B(const int& m_b_in)
        : m_b(m_b_in)
        {}
thd2tn님의 프로필 이미지
thd2tn
Questioner

아 이해했습니다! uniform initialization으로는 생성자가 호출 안되는 줄 알고 있었는데 아니었군요! 정말 감사합니다!

thd2tn1756's profile image
thd2tn1756

asked

Ask a question