0
給出奇怪的鏈接錯誤我想用C++編寫簡單的二叉樹程序使用VS 2012.甚至所有的路徑設置它給我鏈接錯誤,如附件和當我評論在插入函數內註釋掉,它編譯時沒有錯誤。註釋功能正文在VS 2012
// C++ code
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout <<" Simple Binary Tree Examples";
getchar();
return 0;
}
struct node
{
int data;
node *left;
node *right;
};
public class BinaryTree
{
public :
BinaryTree();
~BinaryTree();
void insert(int value);
/*{
if(root==NULL)
{
insert(value,root);
}
else
{
root = new node;
root->data=value;
}
}*/
void delete_tree();
private:
node *root;
void insert(int value,node *leaf);
};
BinaryTree::BinaryTree()
{
root=NULL;
}
BinaryTree::~BinaryTree()
{
delete_tree();
}
void BinaryTree::insert(int value)
{
// If i un-comment the below code.. it gives link error.
/* if(root==NULL)
{
insert(value,root);
}
else
{
root = new node;
root->data=value;
}*/
}
真的不知道什麼可能是錯誤的,因此共享整個代碼。
嘗試新節點();這是有用的嗎? – yossico 2014-09-23 10:34:51
@yossico - 新節點(); - 不工作。 – user1291401 2014-09-23 10:37:31
雖然類定義說它應該存在,但我沒有看到爲delete_tree定義的任何函數體。 – 2014-09-23 10:39:22