티스토리 뷰
#
위임 생성자(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 |
댓글