0

I have a generic linked list class LList<T> with a LList<T>::insert() method for inserting a sorted Node. I would like to specialize the insert() function to have different sorting when the type is std::string, but I get an error:

LINK1169 "one or more multiply defined symbols found"

Below is the relevant code which yields that error:

LinkedList.h

template<typename T>
class LList
{
private:
    struct LLNode
    {
        //node code
    };
    LLNode* head, * tail;
public:
    LList<T>() : head(nullptr), tail(nullptr) {}
    ~LList<T>() {}

    //generic function, trying to specialize
    void insert(const T&);
};

LinkedList.cpp

//definitions of generic insert function
template<typename T>
void LList<T>::insert(const T& newData)
{
    //code
}

//I would like to specialize as follows 
void LList<std::string>insert(const std::string& newData)
{
    //code
}

I tried adding another function definition to the Linked List class in the .h, as is done for generic function specialization outside of classes:

void LList<std::string>::insert(const std::string&);

But that just yields 4 new errors, all on that new line:

'string': is not a member of 'std'
'void LList<std::string>::insert(const T &)': member function ready defined or declared
missing type specifier - int assumed. Note C++ does not support default-int
syntax error: missing ',' before '&'

Is there a way for me to specialize the insert() member function similar to specializing templates normally?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
camdenmcgath
  • 166
  • 1
  • 9

0 Answers0