《程序员》第8期中《在C++中计算对象个数》一文的疑问?
文中有一段代码:
template<typename T>
class Counter{
public:
Counter(){++count;}
Counter(const Counter&){++count;}
~Count(){--count;}
static size_t howmany()
{return count;}
private:
static size_t count;
};
template<typename T>
size_t
Counter<T>::count=0;
实现部分:
classs Widget{
public:
......
static size_t howmany();
{return Counter<Widget>::howmany();}
private:
....
Counter<Widget> c;
};
1)他用的模板声明为什么是template<typename T>而不是template<class T>?
2)在Counter类中为什么没出现T
3)template<typename T>
size_t是什么意思?
4)Counter<Widget>怎么实现?