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);
}
}