A Question of Template class

Hi all, there is link error confuse me, I have a rbtree.h file like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template <class K, class V> 
class RbTree
{
public:
    RbTree();
    RbTree(K &Key, V &Value);
    virtual ~RbTree();
    bool InsertData(const K &Key, const V &Value);
    bool DeleteData(K &Key);
    V SearchValue(K &Key);

private:
    RbTreeNode<K, V> *CreateRbTreeNode(K &Key, V &Value);

    RbTreeNode<K, V> *pTreeRoot;
    const RbTreeNode<K, V> NullNode;
    const RbTreeNode<K, V> * const NULL_NODE_PTR;
};


And rbtree.cpp like :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
......
template <class K, class V>
RbTree<K, V>::RbTree():NULL_NODE_PTR(&NullNode),pTreeRoot(NULL_NODE_PTR)
{
    return;
}

template <class K, class V>
RbTree<K, V>::RbTree(K &Key, V &Value)
{
    RbTree();
    InsertData(Key, Value);
}


template <class K, class V>
RbTree<K, V>::~RbTree()
{

}

......


And last in main.cpp :
1
2
3
4
5
6
7
int main(int argc, char* argv[])
{ 
    RbTree<int, char> Tree;

    //Tree.InsertData(1, 'a');
    return 0;
} 


So I get such error:
1>main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall RbTree<int,char>::~RbTree<int,char>(void)" (??1?$RbTree@HD@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall RbTree<int,char>::RbTree<int,char>(void)" (??0?$RbTree@HD@@QAE@XZ) referenced in function _main

why it can't find the construct and desstruct function?
Any one can help me? thanks
Last edited on
You have to put the code for the template in the header file; it cannot be in the .cpp file.
Topic archived. No new replies allowed.