在模版中使用
比如list<int>,是在传递类型,在程序编译期用<int>进行实例化。
声明类模版
template <typename T> MyClass
{
...
}
使用:
MyClass<int>;
可以传递参数
template <typename T, int m, int n> MyClass
{
enum {rows = m, cols = n};
}
在编译器就指定了m和n的值。
比如list<int>,是在传递类型,在程序编译期用<int>进行实例化。
template <typename T> MyClass
{
...
}
使用:
MyClass<int>;
template <typename T, int m, int n> MyClass
{
enum {rows = m, cols = n};
}
在编译器就指定了m和n的值。