Template class specialization

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 set up a method findfor a specific class.

So, when I do my specialization on a template, do I need to rewrite the code for the implementation of the hole template or just t * find (for example, with a subclass)?

This is the first time I create my own template;)

Help will be appreciated.

+3
source share
1 answer

In this case, you can only specialize a member function

template<> inline MyType *LinkedList<MyType>::find(const char *name) { 
    /* ... */ 
}
+8
source

Source: https://habr.com/ru/post/1781700/


All Articles