GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-May-2008, 01:54
pfanning pfanning is offline
Awaiting Email Confirmation
 
Join Date: Oct 2007
Posts: 39
pfanning is on a distinguished road

Build error with Binary Search tree


Hi,

I am getting under way on this new project involving binary search trees and am getting these two Build errors in VC++:

LAB5.OBJ : error LNK2001: unresolved external symbol "public: __thiscall Binary_tree<struct datanode>::Binary_tree<struct datanode>(void)" (??0?$Binary_tree@Udatanode@@@@QAE@XZ)

and

LAB5.OBJ : error LNK2001: unresolved external symbol "public: __thiscall Binary_node<struct datanode>::Binary_node<struct datanode>(struct datanode const &)" (??0?$Binary_node@Udatanode@@@@QAE@ABUdatanode@@@Z )

It seems to me that there is a problem with two of the public functions in class Binary_tree, but I can't figure out the problem. Can you tell me where I am going wrong? IUf you can, I'd be most appreciative.

Here is the code I have so far:

CPP / C++ / C Code:
#include <iostream>
#include <fstream> // for files in C++ 
#include <stdlib.h> //to be able to use system("cls");
#include <cassert> // used to detect file errors 


using namespace std;


template <class Entry>
struct Binary_node
{
	Entry data;
	Binary_node<Entry> *left;
	Binary_node<Entry> *right;
	Binary_node(); //constructors
	Binary_node(const Entry &x);
};

template <class Entry>
class Binary_tree
{
   public:
		   Binary_tree();
		   void insert(const Entry & );
		   void recursive_insert (Binary_node<Entry>*& sub_root, const Entry & data);
		   void fill_tree();
		   //void inorder() const;
		   //void preorder() const;
		   //void descending() const;
		   //void postorder() const;
		   //int size() const;
		   //float average() const;
		   //void search (int target_key, Binary_node<Entry> * & target_pointer);
		   //bool remove (int target);
   private:
	       Binary_node<Entry> *root;
};

template <class Entry>
Binary_node<Entry>::Binary_node()
{ left=right=NULL;}



struct datanode
{	int key;
	float gpa;
};

void holdscreen() //holds the screen until enter is pressed
{
	cin.ignore();
	cin.ignore();
}

int menu( );

int main()
{	
	Binary_tree<datanode> tree;
	datanode data;
//	Binary_node<datanode> *pointer;
	int choice, key;
	float gpa;

	do
	{	
		system("cls");
		choice = menu();
		switch(choice)
		{	
			case 1:	 tree.fill_tree(); break;
			case 2:  {  cout<<"Enter key and gpa: ";
				        cin>>key>>gpa;
						data.key = key;
						data.gpa = gpa;
						tree.insert(data);
					 }  break;
		/*	case 3:  tree.inorder(); holdscreen(); break;
			case 4:  tree.preorder(); holdscreen(); break;
			case 5:  tree.postorder(); holdscreen(); break;
			case 6:  tree.descending(); holdscreen(); break;
			case 7:  {  cout<<"Size= "<<tree.size()<<endl; holdscreen(); } break;
			case 8:  {  cout<<"Average= "<<tree.average()<<endl;
						holdscreen(); } break;
			case 9:  {  cout<<"Enter key to search for: ";
						cin>>key;
						tree.search(key, pointer);
						if (pointer == NULL)  cout<<"NOT FOUND\n";
						else cout<<"key= "<<pointer->data.key<<" gpa= "<<pointer->data.gpa<<endl;
					 }  holdscreen(); break;
			case 10: {  cout<<"Enter key of node to delete: ";
						cin>>key;
						if ( ! tree.remove(key) )
						{
							cout<<"NOT FOUND\n";
							holdscreen();
						}   break;
					 }
			case 11: break; 
			default: {cout<<"Invalid Choice\n"; holdscreen();}*/
		}
	} while (choice != 11);

  return 0;
}


int menu( )
{ //pre: there is no menu on screen
  //post: user menu on screen

int choice;
system("cls");
cout<<"	LAB5 MENU"<<endl;
cout<<" 1.  Fill tree from file lab5.in"<<endl;
cout<<" 2.  Insert a node into the tree"<<endl;
cout<<" 3.  Print KEYS ONLY in ascending order"<<endl;
cout<<" 4.  Print KEYS with GPAs in preoder"<<endl;
cout<<" 5.  Print KEYS with GPAs in postorder"<<endl;
cout<<" 6.  Print KEYS with GPAs in descending order"<<endl;
cout<<" 7.  Count nodes in tree"<<endl;
cout<<" 8.  Calculate average of GPAs in tree"<<endl;
cout<<" 9.  Search for a KEY in the tree"<<endl;
cout<<" 10. Delete a node from the tree."<<endl;
cout<<" 11. Quit"<<endl;
cout<<" Enter choice: ";
cin>>choice;
return choice;
}

template <class Entry>
void Binary_tree<Entry>::insert (const Entry &data)
{  
	recursive_insert(root,data);
}
					 
template<class Entry>
void Binary_tree<Entry>::recursive_insert (Binary_node<Entry>*& sub_root, const Entry & data)
{
	if (sub_root==NULL) sub_root=new Binary_node<Entry> (data);
	else if (data.key<sub_root->data.key)
		     recursive_insert(sub_root->left,data);
		 else recursive_insert(sub_root->right,data);
}
	
template<class Entry>
void Binary_tree<Entry>::fill_tree()	
{
	datanode fileData;
	int fileKey;
	float fileGpa;

	ifstream infile ("c:\\temp\\LAB5.IN", ios::in);
	assert (!infile.fail()); //stops program if file doesn't open

	while (infile>>fileKey)
	{
		infile>>fileKey;
		infile>>fileGpa;
		fileData.key = fileKey;
		fileData.gpa = fileGpa;
		insert(fileData);
	}
	infile.close(); // done with infile so we close it here
}
  #2  
Old 16-May-2008, 07:19
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 640
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Build error with Binary Search tree


Code:
LAB5.OBJ : error LNK2001: unresolved external symbol "public: __thiscall Binary_tree<struct datanode>::Binary_tree<struct datanode>(void)" (??0?$Binary_tree@Udatanode@@@@QAE@XZ)
This means that you have declared a constructor for Binary_tree but you have not created the method.

Code:
LAB5.OBJ : error LNK2001: unresolved external symbol "public: __thiscall Binary_node<struct datanode>::Binary_node<struct datanode>(struct datanode const &)" (??0?$Binary_node@Udatanode@@@@QAE@ABUdatanode@@@Z )
This is similar to the other one in that you declared a copy constructor for Binary_node but did not create it.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Link List In C Peter_APIIT C Programming Language 33 12-Jun-2008 13:33
Binary Search Tree Peter_APIIT C Programming Language 13 19-Mar-2008 23:11
can anyone help me with my tree :) bioeng_mtm C++ Forum 5 22-Apr-2006 12:50
Binary Search Tree in C++ rpg3 C++ Forum 5 02-Apr-2006 09:53
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 10:34

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:55.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.