析构函数 无法解析的外部符号
mzoj 2014-10-20 01:30:37 小弟想写一个二叉树的算法 可是编译总是说无法解析的外部符号 求大神指导
// header.h
#ifndef _H_HEADER_H_
#define _H_HEADER_H_
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#endif
// BinaryTree.h
#ifndef _H_BINARYTREE_H_
#define _H_BINARYTREE_H_
template< class T >
class BinaryTree;
template< class T >
class BinaryTreeNode
{
public:
BinaryTreeNode() : lChild( NULL ) , rChild( NULL ) {}
BinaryTreeNode( T x , BinaryTreeNode< T > * l = NULL , BinaryTreeNode< T > * r = NULL ) : data( x ) , lChild( l ) , rChild( r ) {}
friend class BinaryTree< T >;
private:
T data;
BinaryTreeNode< T > * lChild;
BinaryTreeNode< T > * rChild;
};
template< class T >
class BinaryTree
{
public:
BinaryTree() : root( NULL ) {}
~BinaryTree(){ deleteBinaryTree( root ); }
BinaryTree< T > * getRoot() const { return root; }
void deleteBinaryTree( BinaryTreeNode< T > * );
private:
BinaryTreeNode< T > * root;
};
#endif
// BinaryTree.cpp
#include "header.h"
#include "BinaryTree.h"
template< class T >
void BinaryTree< T > ::deleteBinaryTree( BinaryTreeNode< T > * r )
{
if( r )
{
deleteBinaryTree( r ->lChild );
deleteBinaryTree( r ->rChild );
delete r;
}
}
// main.cpp
#include "header.h"
#include "BinaryTree.h"
int main( void )
{
BinaryTree< char > bTree;
return 0;
}