[英]Specializing a template class
I just created a template class 我刚刚创建了一个模板类
template< typename T >
class LinkedList {
private:
struct LinkedListElement {
T *m_data;
LinkedListElement *m_next;
};
LinkedListElement *head;
public:
void insert(T *elem);
void remove(T *elem);
T *find(const char *name);
};
and I want to customize what find
method does for a certain class. 我想自定义
find
方法对某个类的作用。
So, when I do my template specialization do I have to re-write the hole template implementation code or just t *find(like when subclassing)? 那么,当我进行模板专业化时,我是否必须重新编写孔模板实现代码或者只是t * find(比如子类化时)?
This is the first time I create my own template;) 这是我第一次创建自己的模板;)
Help would be appreciated. 帮助将不胜感激。
For this case, you can specialize the member function only 对于这种情况,您只能专门化成员函数
template<> inline MyType *LinkedList<MyType>::find(const char *name) {
/* ... */
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.