Wednesday, August 28, 2019

c++ - Template class constructor

Ok guys...
I have following class


#include 
template >
class BinarySearchTree {
struct TNode {
TValue value;
TNode *pLeft;
TNode *pRight;
};
public:
BinarySearchTree();
~BinarySearchTree();
. . .
private:
TNode *pRoot;
. . .
};

then in my .cpp file i defined the ctor/dtor like this:


template 
BinarySearchTree::BinarySearchTree() : pRoot(0) {}
template
BinarySearchTree::~BinarySearchTree() {
Flush(pRoot);
}

my main function:


int main() {
BinarySearchTree obj1;
return 0;
}

and i get following linkage error:


public: __thiscall BinarySearchTree>::BinarySearchTree >(void)

i tried to put the constructor definition into the header file and i get no error. only if i try to define it in the cpp file.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...