• Class Template function template와 유사하다.

    template <typename Type [=int] > //default 지정 가능; 함수에선 x
    class Stack{
    private:
    	Type items[4];
    };
    
    • 사용시 Stack<int> ints; Stack<string>strings; 이런식으로.
      • Stack ss; 같은거 안됨; explicit 하게 <int>선언해야 함.
    • non-type / expression / argument
    template <class T, int n [=10] > //default 지정 가능; 함수도 가능
    class aa
    {
    	T arr[n];
    };
    

    이런 식이면 n이 컴파일 단계에서 정해져야 한다. 따라서 aa<double, 12> arr1 이런식으로 명시해 주어야 함.

    • 장점: 동적 할당 안해도 됨, 빠르다

    • 단점: 값이 다를 때마다 다른 코드를 만들기 때문에 무겁다.

    • template with drived class

    • 잘 활용하자.

      Untitled

    • Explicit Specializations 예외 처리하고 싶을 때 사용한다(함수와 비슷)

      Untitled

    • Partial Specializations 몇개만 예외처리할 때 사용 함수에서는 사용하지 못한다!!!

      Untitled

    • typedef, using using은 typedef 와 비슷하게 동작함

      • using은 템플릿에서도 사용 가능

        Untitled