책의 예제를 쳤는데.. 이해가 안가기도 하고 에러가 나기도하고.

찬밥의 이미지

오타는 없어 보이는데.. 실행이 안되내요..
문법도 쫌 이해가 안되고..
tempparm.cpp

#include <iostream>
using namespace std;
#include "stacktp.h"

template <template <typename T> class Thing>
class Crab
{
private:
	Thing<int> s1;
	Thing<double> s2;
public:
	Crab() {}
	bool push(int a, double x) { return s1.push(a) && s2.push(x); }
	bool pop(int & a, double & x) { return s1.pop(a) && s2.pop(x); }
};

int main()
{
	Crab<Stack> nebula;
	int ni;
	double nb;

	while (cin >> ni >> nb && ni > 0 && nb > 0)
	{
		if(!nebula.push(ni, nb))
			break;
	}

	while(nebula.pop(ni, nb))
		cout << ni << ", " << nb << endl;
	cout << "프로그램을 종료합니다.\n";

	return 0;
}

stacktp.h

#ifndef STACKTP_H_
#define STACKTP_H_
template <class Type>
class Stack
{
	private:
		enum { MAX = 10};
		Type items[MAX];
		int top;
	public:
		Stack();
		bool isempty() const;
		bool isfull() const;
		bool push(const Type & item);
		bool pop(Type & item);
};

template <class Type>
Stack<Type>::Stack()
{
	top = 0;
}

template <class Type>
bool Stack<Type>::isempty() const
{
	return top == 0;
}

template <class Type>
bool Stack<Type>::isfull() const
{
	return top == MAX;
}

template <class Type>
bool Stack<Type>::push(const Type & item)
{
	if (top < MAX)
	{
		items[top++] = item;
		return true;
	}
	else
		return false;
}

template <class Type>
bool Stack<Type>::pop(Type & item)
{
	if (top > 0)
	{
		item = items[--top];
		return true;
	}
	else
		return false;
}

#endif

tempparm.cpp 중에서

템플릿 나오는 부분이요..

template <template <typename T> class Thing>

이 부분 이해가 안가는데요?
뭔뜻일까요??

또.. 템플릿 얘기 이해가 ㅡ_ㅡ;; 책을 여러번 읽는 편이 좋을까요.. 이거참...
책만 봐서는 도대체 뭔소린지 -_-;

doldori의 이미지

template <class Thing> class Crab;

이건 무슨 뜻인지 아시죠? Crab은 클래스 템플릿인데 type parameter로
쓰이는 Thing은 어떤 형을 나타내는 이름입니다. 이러면 Crab<int>,
Crab<int*>, 심지어는 Crab< Crab<int> > 로도 쓰일 수 있습니다.

template <template <typename T> class Thing>
class Crab;

이것은 type parameter인 Thing 자체가 type parameter 하나만을
갖는 템플릿 클래스여야 함을 뜻합니다. 말이 좀 복잡하죠? :)
따라서

template<typename U> AClass;
template<typename T, typename U> BClass;
Crab<AClass> aCrab;   // ok
Crab<BClass> bCrab;   // error
Crab<int>  intCrab;   // error

가 됩니다.