#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include<algorithm>
using namespace std;
// Modern C++ (C++11 부터 나온 아이들)
// 중괄호 초기화 { }
class Knight {
public:
Knight() {
cout << "기본생성자 호출" << endl;
}
// initializer_list: 초기화할 때 사용하는 리스트
// 다만 해당 생성자를 생성하면 중괄호 안의 인자 개수와는 상관 없이 무조건 아래 생성자가 호출됨
Knight(initializer_list<int> li) {
cout << "initializer list 호출" << endl;
}
Knight(int a, int b) {
cout << "Knight(int a,int b) 호출" << endl;
}
};
int main()
{
int a = 0;
int b(0);
int c{ 0 };
Knight k1;
//Knight k2 = k1; // 대입 연산자가 아님(복사 연산자가 실행됨)
//k2 = k1; // 대입 연산자가 실행됨
Knight k3{ k1 };
int arr[] = { 1,2,3,4 };
// 중괄호 초기화
// 1) vector 등 container과 잘 어울린다.
vector<int> v3{ 1,2,3,4,5,6 }; //vector에 1,2,3,4를 push_back한 것과 같다
// 2) 축소 변환 방지
int x = 0;
double y(x);
//double z{ x }; //축소 변환을 애초에 방지해버림
//int z{ y };
// 3) Bonus
Knight k4(); //기본 생성자를 호출한 것이 아닌 함수를 선언해버린 것 같은 느낌
Knight k5{1,2,3,4,5}; //기본 생성자 호출은 중괄호를 이용
// 괄호 초기화 ()를 기본으로 간다
// - 전통적인 C++ (거부감이 없음)
// - vector 등 특이한 케이스에 대해서만 { } 사용
// 중괄호 초기화 {}를 기본으로 간다
// - 초기화 문법의 일치화
// - 축소 변환 방지
return 0;
}