티스토리 뷰

technote/C++

C++ 위임 생성자

HTS3 2018. 10. 15. 01:27

#

위임 생성자(delegating constructor)는 배울 때 미국에서 swift를 하며 매일 같이 생각했던 delegate와 같았다.


constructor 에서 같은 클래스 내의 다른 constructor를 쓸 수 있는 기능을 delegating cnostructor라고 한다.


ex)


class Student

{

private:

int id;

int score;


public:

//일반적인 constructor

Student( const int& id_input, const int& score_input) : id(id_input), score(score_input) {}


//delegating constructor를 사용

Student(const int& id_input)

{

Student(id_input, 100);

}

}

'technote > C++' 카테고리의 다른 글

정적라이브러리 공유라이브러리  (0) 2018.10.17
cmake를 이용해 빌드하기  (0) 2018.10.17
g++ 기본 옵션  (0) 2018.10.16
C++ Consturctor (생성자) 돌아보기  (0) 2018.08.02
C++ private 생성자  (0) 2018.07.30
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함