- 중복 생성자(생성자 오버로딩)이 가능하다
- 디폴트 인수가 가능하다
- 초기화 리스트와 디폴트 인수를 동시에 사용할 수도 있다
초기화 리스트와 디폴트 인수 동시에 사용하기
#include <iostream>
using namespace std;
class Person{
private:
string name;
int age;
public:
Person(string name = "a", int age = 20): name{name}, age{age} { }
void print(){
cout << "Person[name=" << name << ", age=" << age << "]" << endl;
}
};
int main()
{
Person a;
a.print();
Person b { "b", 19};
b.print();
return 0;
}
'C++' 카테고리의 다른 글
[C++] vector 정리 (0) | 2023.09.16 |
---|---|
[C++] 라이브러리 별 함수 정리 (0) | 2023.09.16 |
[C++] 연산자 정리 (0) | 2023.09.16 |
[VSCode C++] Undefined symbols for architecture arm64: (0) | 2023.09.16 |
[VSCode C++] 헤더파일 못 찾을 때 (0) | 2023.09.16 |