Error for program

i get error like this
1
2
3
4
5
6
1>main.obj : error LNK2005: "public: __thiscall Tree::Tree(void)" (??0Tree@@QAE@XZ) already defined in cd.obj
1>main.obj : error LNK2005: "public: bool __thiscall Tree::Empty(void)" (?Empty@Tree@@QAE_NXZ) already defined in cd.obj
1>main.obj : error LNK2005: "void __cdecl addNode(struct TreeNode * &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?addNode@@YAXAAPAUTreeNode@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in cd.obj
1>main.obj : error LNK2005: "void __cdecl Print(struct TreeNode * &)" (?Print@@YAXAAPAUTreeNode@@@Z) already defined in cd.obj
1>main.obj : error LNK2005: "public: void __thiscall Tree::Display(void)" (?Display@Tree@@QAEXXZ) already defined in cd.obj
1>C:\Users\User\Desktop\Inti\Applied\Assignment 5\Debug\Assignment 5.exe : fatal error LNK1169: one or more multiply defined symbols found


what my tree is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
struct TreeNode{
	string cdTitle;
	TreeNode *left;
	TreeNode *right;
};

class Tree{
private:
	TreeNode *root;
public:
	Tree();
	~Tree();
	
	bool Empty();
	void Display();

};

Tree :: Tree (){
	root = NULL;
}

bool Tree :: Empty(){
	if ( root == NULL )
		return true;
	else
		return false;
}

void addNode( TreeNode*& tree , string title ){
	if( tree == NULL ){
		tree = new TreeNode;
		tree->left = NULL;
		tree->right = NULL;
		tree->cdTitle = title;
	}
	else if( title < tree->cdTitle )
		addNode( tree->left , title );
	else
		addNode( tree->right , title );
}


void Print( TreeNode*& tree ){
	if( tree != NULL ){
		Print( tree->left );
		cout << tree->cdTitle;
		Print( tree->right );
	}
}

void Tree :: Display(){
	Print ( root );
}
You just missed the definition of destructor(~Tree())...
still got a error for
1
2
3
4
5
6
7
8
1
1>main.obj : error LNK2005: "public: __thiscall Tree::Tree(void)" (??0Tree@@QAE@XZ) already defined in cd.obj
1>main.obj : error LNK2005: "void __cdecl Destroy(struct TreeNode * &)" (?Destroy@@YAXAAPAUTreeNode@@@Z) already defined in cd.obj
1>main.obj : error LNK2005: "public: __thiscall Tree::~Tree(void)" (??1Tree@@QAE@XZ) already defined in cd.obj
1>main.obj : error LNK2005: "public: bool __thiscall Tree::Empty(void)" (?Empty@Tree@@QAE_NXZ) already defined in cd.obj
1>main.obj : error LNK2005: "void __cdecl addNode(struct TreeNode * &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?addNode@@YAXAAPAUTreeNode@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in cd.obj
1>main.obj : error LNK2005: "void __cdecl Print(struct TreeNode * &)" (?Print@@YAXAAPAUTreeNode@@@Z) already defined in cd.obj
1>main.obj : error LNK2005: "public: void __thiscall Tree::Display(void)" (?Display@Tree@@QAEXXZ) already defined in cd.obj
1>C:\Users\User\Desktop\Inti\Applied\Assignment 5\Debug\Assignment 5.exe : fatal error LNK1169: one or more multiply defined symbols found



and my tree constructor
1
2
3
4
5
6
7
8
9
10
11
void Destroy( TreeNode*& tree ){
	if( tree != NULL ){
		Destroy (tree->left);
		Destroy (tree->right);
		delete tree;
	}
}

Tree :: ~Tree(){
	Destroy (root);
}
it's working fine on my PC....
I believe you're using Visual C++. My suggestion is to create a new project and add your files again to see if you run into the same error. Essentially, your errors are stating that all of your class functions have already been defined and you're simply trying to redefine them. This usually comes from 1) MSVC messing up (happens a lot) 2) you are #include'ing your tree.cpp along with compiling it, or 3) you have copied the function definitions elsewhere in your code.

It's hard to say specifically what's causing the problem, but I'd start with my suggestion and if that doesn't work, I suggest copy/pasting each file here and include the name of the file as well.
Topic archived. No new replies allowed.