0

I am overloadin the = Operator so I can assign an Obj to another Obj.
he Errors are:
Error 1 error C2556: 'void BSTree::operator =(const BSTree &)' : overloaded function differs only by return type from 'BSTree &BSTree::operator =(const BSTree &)' c:\users\phil\desktop\c++\cs230\lab5\lab5\lab5\bstree.cpp 157
Error 2 error C2040: 'BSTree::operator =' : 'void (const BSTree &)' differs in levels of indirection from 'BSTree &(const BSTree &)' c:\users\phil\desktop\c++\cs230\lab5\lab5\lab5\bstree.cpp 157
Error 3 error C2662: 'BSTree::GetRoot' : cannot convert 'this' pointer from 'const BSTree' to 'BSTree &' c:\users\phil\desktop\c++\cs230\lab5\lab5\lab5\bstree.cpp 160
Error 4 error C2660: 'BSTree::FreeTree' : function does not take 1 arguments c:\users\phil\desktop\c++\cs230\lab5\lab5\lab5\bstree.cpp 160
Error 5 error C2662: 'BSTree::GetRoot' : cannot convert 'this' pointer from 'const BSTree' to 'BSTree &' c:\users\phil\desktop\c++\cs230\lab5\lab5\lab5\bstree.cpp 161
Error 6 error C2664: 'BSTree::CopyTree' : cannot convert parameter 1 from 'TreeNode *' to 'TreeNode *&' c:\users\phil\desktop\c++\cs230\lab5\lab5\lab5\bstree.cpp 161

I dont know where I am going wrong. any help is cool

Attachments
//=============================================================================
//		INCLUDE FILES
#include <iostream>
#include <cassert>
#include "Contributor.h"
#include "BSTree.h"
using namespace std;
//
///*****************************************************************************
//		BEGINNING OF CLASS MEMBER FUNCTION CODING
//*****************************************************************************
	TreeNode::TreeNode()
	{
		pRight = NULL;
		pLeft = NULL;
		cout<<"Program is in the default Ctor"<<endl;
	}

	TreeNode::TreeNode(Contributor InData)
	{
		Data = InData;
		pRight = NULL;
		pLeft = NULL;
	}

	//TreeNode::TreeNode(const TreeNode & TreeNode)	//could use for delete by copy
	//{

	//}

	TreeNode::~TreeNode()
	{
		cout<<" Treenode Dtor"<<endl;
	}
	
//*********************************************************************************************


	BSTree::BSTree()
	{
		pTree = NULL;	//creates empty BST
		cout<<"Empty Tree created"<<endl;
	}

	BSTree::~BSTree()
	{
		cout<<"BST dtor ran"<<endl;
	}

	bool BSTree::IsEmpty()
	{
		if (pTree == NULL)
			return true;
		else
			return false;
	}

	bool BSTree::FreeTree()
	{
		TreeNode *p = pTree;
		if(p != NULL)
		{
		   PostOrder(p->pLeft);
		   PostOrder(p->pRight);
		   delete p;
		}
		return (IsEmpty());
	}

	void BSTree::Insert(Contributor InData)
	{
		TreeNode *pTrav = pTree;		   //assign pTrav and
		TreeNode *pPrev = pTree;		   //pPrev to pTree

		Contributor Data = InData;					 //assign local Data In's value
		TreeNode *pNew = new TreeNode(Data);	 //create new node to insert
		assert(pNew);							 //check memory allocation

		
			while (pTrav != NULL)
			{
				pPrev = pTrav;					 //move pPrev to pTrav
		
					if (InData < pTrav->Data)		  //if < parameter input 
						pTrav = pTrav->pLeft;	  //move pTrav to left child
					else						  //otherwise
						pTrav = pTrav->pRight;	  //move pTrav to right child
			}	//if pTrav == NULL fall out of while
			
			if (IsEmpty())
				{pTree = pNew;					//assign root node
					cout<<"Root created"<<endl;}
			else if (InData< pPrev->Data)          //if pPrev's data greater
				{pPrev->pLeft = pNew;			//insert at pPrev's pLeft
					cout<<"Left node created"<<endl;}
			else						   
				{pPrev->pRight = pNew;	   
					cout<<"Right node created"<<endl;}
					
		cout<<"End of function"<<endl;
	}			   

	/*bool BSTree::Delete(Contributor InContrib)
	{
	   
	}*/
	
												 
	TreeNode* BSTree::Find(Contributor InData)
	{
		TreeNode *pTrav = pTree;				 //Node pointer pTrav pts at pTree(beg)
		if(IsEmpty() == true)					 //Check is empty once
			cout<<"BST is currently empty"<<endl;
		else											   //loop stops if pTrav finds nothing
			while ((pTrav != NULL) && (pTrav->Data != InData))   //or if Data looked for matches In
			{
				if (InData < pTrav->Data)
					pTrav = pTrav->pLeft;				 //if In less than go left
				else
					pTrav = pTrav->pRight;			   //if In greater than go right
			}		
		return pTrav;

	}

	void BSTree::PreOrder(TreeNode *p)
	{
	   if(p != NULL)
	   {
		   cout<<p->Data;
		   PreOrder(p->pLeft);		
		   PreOrder(p->pRight);
	   }
	}

	void BSTree::PostOrder(TreeNode *p)
	{
	   if(p != NULL)
	   {
		   PostOrder(p->pLeft);
		   PostOrder(p->pRight);
		   cout<<p->Data;
	   }
	}
	
	void BSTree::InOrder(TreeNode *p)
	{
	   if(p != NULL)
	   {
		   InOrder(p->pLeft);
		   cout<<p->Data;
		   InOrder(p->pRight);
	   }
	}
	
	void BSTree::operator = (const BSTree &RHS)
	{
			if (&RHS==this)
				
			FreeTree(RHS.GetRoot());
			CopyTree(GetRoot(), RHS.GetRoot());	
			return *this ;
	}

	void CopyTree(TreeNode* &copy, const TreeNode* origTree)
	{
		if (origTree == NULL)
			copy = NULL;
		else
		{
			copy = new TreeNode;
			copy->Data = origTree->Data;
			CopyTree(copy->pLeft, origTree->pLeft);  //recursive copy after root
			CopyTree(copy->pRight, origTree->pRight);
		}
	}
//******************************************************************************
//		END OF CLASS MEMBER FUNCTION CODING
//******************************************************************************
//		FRIEND FUNCTION CODING
//******************************************************************************
//=================================================================================
//		PROCESS THIS FILE ONLY PER PROJECT
#ifndef BSTREE_H	//Avoid duplicate compilations
#define BSTREE_H	//
//=================================================================================
//			INCLUDE FILES
#include "Contributor.h"
//=================================================================================
//			CONSTANT DEFINITION
//=================================================================================
//		GLOBAL CONSTANTS/OBJECTS
//
//=================================================================================
//	START OF CLASS DEFINITIONS
//=================================================================================
class TreeNode
{
public:
	TreeNode();
	TreeNode(Contributor InData);
	TreeNode(const TreeNode & TreeNode);	//could use for copy deletions
	~TreeNode();
	//void Print();
	Contributor Data;
	TreeNode *pLeft;
	TreeNode *pRight;
	/* local variables TreeNode *pRMPrev, *pRM, *pLMPrev, *pLM to delete*/
};

class BSTree
{
public:
	BSTree();
	~BSTree();
	bool IsEmpty();
	bool FreeTree();
	void Insert(Contributor);
	bool Delete(Contributor);
	TreeNode* Find(Contributor InData);  //looks for indiv TNode
	TreeNode* GetRoot() {TreeNode *root = pTree; return root;}
	void PreOrder(TreeNode *p);		  //these have the << functions in them
	void PostOrder(TreeNode *p);
	void InOrder(TreeNode *p);
	BSTree &operator = (const BSTree &RHS);
	void CopyTree(TreeNode* &copy, const TreeNode* origTree);

private:
	TreeNode *pTree;
};

//=================================================================================
//		END OF CLASS DEFINITION
#endif
//=================================================================================
//		END OF HEADER FILE
//=================================================================================
//***************************************************************
// TITLE:                      	Contributor	
// FILE:						Contributor.cpp
// PREPARED FOR:               	CS230 Section <section number>
// PROGRAMMER(S):              	< Phillip Harris>
// DEVELOPMENT DATE:           	< 07/09/08>
// COMPILER USED:      		    <MS visual studio 2005>
// TARGET PLATFORM:         	< WIN XP >
//================================================================
//                           PROJECT FILES
//    	contributor.h, contributor.cpp,	Lab1.cpp
//================================================================
//                          REVISION HISTORY
//   DATE     PROGRAMMER            DESCRIPTION OF CHANGES MADE
//	<07/08/08	Phil Harris				Original >
//================================================================

#include <iostream>
#include <string>
#include <iomanip>
#include "Contributor.h"
using namespace std;

///c-tor implementation 
 int num =1;
Contributor::Contributor()
{	
	Name = ""; 
	Contribution = 0.0f; 
	Sex = None;
	IDKey = 0; 
}
//copy C-tor
Contributor::Contributor(string InContrib, double InContribution, Gender InSex, int InIDKey)
{
	Name= InContrib;
    Contribution= InContribution;
	Sex = InSex;
    IDKey= InIDKey;
}
Contributor::Contributor(const Contributor &CCContrib)
{ 
	Name = CCContrib.Name;
	Contribution= CCContrib.Contribution;
	Sex = CCContrib.Sex;
	IDKey = CCContrib.IDKey;
}
ostream &operator <<(ostream & Out,Contributor &InContrib)
 	{  
     	//Out<<endl<<num<<"\tName of the Contributor? " <<endl;
		Out<<"\tName: " <<InContrib.Name <<endl;
		Out<<"\tID Number: " <<InContrib.IDKey<<endl;
		//Out<<endl<<num<<endl;
        Out<<"\tContribution: "<<InContrib.Contribution<<endl;
		Out<<"\tGender: ";	
 			switch (InContrib.Sex)
			{
				case Male: Out<<" Male ";break; 
				case Female: Out<<" Female ";break;
				//default: Out<<"NONE";break;
     		}
  		num++;
		Out<<endl<<endl; 
		return Out; 
	}
/*istream &operator >> (istream &In,Contributor &InContrib)
	{
		int SelSex = 0;//selection of gender
		In.clear();
		In.ignore(In.rdbuf()->in_avail(), '\n'); 
		cout<<"\tEnter Contirbutors Name: ";
		getline(In,InContrib.Name); 

		cout<<"\tEnter the amount of "<<InContrib.Name <<"'s contribution ";
		In>>InContrib.Contribution; 
		
		cout<<"\tNow Enter an ID# for "<<InContrib.Name<<" ";
		In>>InContrib.IDKey;
		
		cout<<"\twhat is "<<InContrib.Name<<"'s Gender? "<<endl;
		cout<<"\t1. Male. \n\t2. Female \n\t3. None\n\n";
		In >> SelSex;
		switch(SelSex)
			{
				case 1: SelSex = Male; break;
				case 2: SelSex = Female; break;
				case 3: SelSex = None; break;
			}
		return In;
	}
	*/
Contributor &Contributor::operator = (const Contributor & RtSide)
{
	if(this != &RtSide)
	{
		Name = RtSide.Name;/////
		Contribution = RtSide.Contribution;
		Sex = RtSide.Sex;
		IDKey = RtSide.IDKey;/////
	}	
	return *this;
}
bool Contributor::operator <(const Contributor & RtSide)
	{return (Contribution <RtSide.Contribution);}

bool Contributor::operator >(const Contributor & RtSide)
	{return (Contribution <RtSide.Contribution);}	

bool Contributor::operator ==(const Contributor & RtSide)
	{return ((Name == RtSide.Name)&&(Contribution==RtSide.Contribution)&&(Sex== RtSide.Sex));
	}
bool Contributor::operator !=(const Contributor & RtSide)
	{return((Name != RtSide.Name)||(Contribution!=RtSide.Contribution)||(Sex != RtSide.Sex));
	}
// TITLE:                      	Contributor	
// FILENAME:                   	Contributor.h
// PREPARED FOR:               	CS230 Section <section number>
// PROGRAMMER(S):              	< Phillip Harris>
// DEVELOPMENT DATE:           	< 07/09/08>
// COMPILER USED:      			<MS visual studio 2005>
// TARGET PLATFORM:         	< WIN XP >
//================================================================
//                           PROJECT FILES
//    	contributor.h ,contributor.cpp, Lab1.cpp
//================================================================
//                          REVISION HISTORY
//   DATE     PROGRAMMER            DESCRIPTION OF CHANGES MADE
//	<07/08/08	Phil Harris				Original >
//
//================================================================
//              PROCESS THIS FILE ONLY ONCE PER PROJECT
#ifndef	CONTRIBUTOR_H 
#define	CONTRIBUTOR_H
#include <iostream>
#include <string>
//#include "myQueue.h"
using namespace std;
//================================================================
//CONSTANT DEFINITIONS
enum Gender {Male=0, Female, None};                       
class Contributor
{
friend ostream &operator <<(ostream & Out,Contributor &InContrib);
friend istream &operator >>(istream & In, Contributor &InContrib);

public:	
	Contributor();
	Contributor(string InContrib, double InContribution, Gender inSex, int InIDKey);
	Contributor(const Contributor &CCContrib);
	
/////Overloaded Operators
	Contributor &operator=(const Contributor & RtSide);
	bool operator <(const Contributor & RtSide);
	bool operator >(const Contributor & RtSide);
 	bool operator ==(const Contributor & RtSide);
	bool operator!=(const Contributor & RtSide);
	bool insertNode(Contributor i);

private:
	string Name;
	double Contribution;
	Gender Sex;
	int IDKey;	
};

#endif
//		INCLUDE FILES
#include <iostream>
#include <cassert>
#include "Contributor.h"
#include "BSTree.h"
	using namespace std;
//
//=============================================================================
//		FUNCTION PROTOTYPES (IF ANY)
//
//*****************************************************************************
//		BEGINNING OF MAIN PROGRAM CODE
//*****************************************************************************
int main ()
{
	cout<<"Test One, ctor/dtors"<<endl;
	BSTree MyTree;
	//************************************************
	//this sets up all my objs
	Contributor obj1("Philip", 15.67, Male, 1);
	Contributor obj2("Raymond", 19.48, Male, 5);
	Contributor obj3("Dottie", 19.52, Female, 7);
	Contributor obj4("Hannah", 19.99, Female, 2);
	Contributor obj5("Rachel", 20.01, Female, 8);
	Contributor obj6("Joanna", 19.69, Female, 4);
	Contributor obj7("Stacie", 19.71, Female, 10);
	Contributor obj8("David", 19.72,Male, 11);
	TreeNode DNode;
	TreeNode ONode(obj8);
	cout<<endl;

	cout<<"Test two, check IsEmpty"<<endl;
	cout<<"Is empty?"<<boolalpha<<MyTree.IsEmpty()<<endl;
	cout<<endl;
	
	cout<<"Test Three, Insert"<<endl;
	MyTree.Insert(obj7);
	MyTree.Insert(obj8);
	MyTree.Insert(obj2);
	MyTree.Insert(obj5);
	MyTree.Insert(obj4);
	MyTree.Insert(obj3);
	MyTree.Insert(obj6);
	MyTree.Insert(obj1);
	cout<<endl;
	
	cout<<"Test 4: "<<"Is empty?"<<boolalpha<<MyTree.IsEmpty()<<endl<<endl;

	/*cout<<"Test 5: "<<endl;
	cout<<"Result of obj7 search: "<<MyTree.Find(obj7)<<endl;	 
	cout<<"Result of obj8 search: "<<MyTree.Find(obj8)<<endl;			 
	cout<<"Result of obj2 search: "<<MyTree.Find(obj2)<<endl;
	cout<<"Result of obj3 search: "<<MyTree.Find(obj3)<<endl;			 
	cout<<"Result of obj4 search: "<<MyTree.Find(obj4)<<endl;
	cout<<"Result of obj5 search: "<<MyTree.Find(obj5)<<endl;			 
	cout<<"Result of obj6 search: "<<MyTree.Find(obj6)<<endl;
	cout<<"Result of obj1 search: "<<MyTree.Find(obj1)<<endl<<endl;
	*/	 

	cout<<"Test 6: Traversals/Print"<<endl;			 
	cout<<"Pre-order Traversal: "<<endl;
	MyTree.PreOrder(MyTree.GetRoot());
	cout<<"Post-order Traversal: "<<endl;
	MyTree.PostOrder(MyTree.GetRoot());
	cout<<"In-order Traversal: "<<endl;
	MyTree.InOrder(MyTree.GetRoot());
	cout<<endl;

	cout<<"Test 7:  Assignment operator and Copy Ctor"<<endl;
	BSTree CopyTree(MyTree);
	cout<<"BSTree CopyTree after copy ctor, contents now..."<<endl;
	CopyTree.InOrder(CopyTree.GetRoot());
	BSTree EQTree = MyTree;
	cout<<"BSTree EQTree after assignment op, contents now..."<<endl;
	EQTree.InOrder(EQTree.GetRoot());

return 0;
}
//******************************************************************************
//		END OF MAIN PROGRAM CODE
//******************************************************************************
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

>>I dont know where I am going wrong. any help is cool

The first error tells you what is wrong. You can't have two functions that differ only by their return type. Overloaded functions must have different parameters.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.