出错函数为void BinaryTree_test(),如下:
(1)该函数在BInarySearchTree.h中声明如下:
void BinaryTree_test();
(2)该函数在BInarySearchTree.cpp中定义,如下:
void BinaryTree_test()
{
BinarySearchTree<int> tree;
tree.insert(5);
tree.insert(6);
tree.insert(4);
tree.insert(8);
tree.insert(7);
tree.insert(11);
tree.insert(14);
tree.insert(10);
tree.insert(20);
tree.insert(13);
tree.insert(2);
tree.insert(1);
tree.insert(3);
tree.printHeight();
}
(3)解决措施很简单,只要在函数头添加inline即可,如下:
/*加入了inline*/inline void BinaryTree_test()
{
BinarySearchTree<int> tree;
tree.insert(5);
tree.insert(6);
tree.insert(4);
tree.insert(8);
tree.insert(7);
tree.insert(11);
tree.insert(14);
tree.insert(10);
tree.insert(20);
tree.insert(13);
tree.insert(2);
tree.insert(1);
tree.insert(3);
tree.printHeight();
}