My program is to put different people into different companies and demote(moe down the list).promote(move up list) and so on
Im also guessing each company has its own seperate linked list??
here are my UnsortedType header and cpp, and my ItemType header and cpp files. I know that i have not created a main function but it should still compile with only the error of not having a main...
//ItemType header file
#include <fstream>
#include <cstdlib>
const int MAX_ITEMS = 20;
enum RelationType {LESS,GREATER,EQUAL};
class ItemType
{
public:
ItemType();
RelationType ComparedTo(ItemType) const;
void Print (std::ofstream&) const;
void Initialize(int number);
private:
int value;
};
//ItemType cpp file
#include<fstream>
#include<iostream>
#include<cstdlib>
#include "ItemType.h"
using namespace std;
ItemType::ItemType():value(0)
{
}
RelationType ItemType::ComparedTo(ItemType otherItem) const
{
if(value < otherItem.value)
return LESS;
else if(value > otherItem.value)
return GREATER;
else return EQUAL;
}
void ItemType::Initialize(int number)
{
value = number;
}
void ItemType::Print(std::ofstream& out) const
{
out << value << " ";
}
//UnsortedType header file
#include <iostream>
#include <cstdlib>
#include "ItemType.h"
struct NodeType; // Im not sure exactly where im suppose to declare this and i think this is what is causing the problem
class UnsortedType
{
public:
UnsortedType();
void MakeEmpty();
bool IsFull() const;
int GetLength() const;
ItemType GetItem(ItemType item, bool& found);
void PutItem(ItemType item);
void DeleteItem(ItemType item);
void ResetList();
ItemType GetNextItem();
private:
NodeType* listData;
int length;
NodeType* currentPos;
};
// UnsortedType cpp file
#include "UnsortedType.h"
#include <iostream>
#include <cstdlib>
using namespace std;
struct NodeType // this is where i declared the struct NodeType from above
{
ItemType info;
NodeType* next;
};
void UnsortedType::PutItem(ItemType item)
{
NodeType* location;
location = new NodeType;
location->info = item;
location->next = listData;
listData = location;
length++;
}
UnsortedType::UnsortedType()
{
length = 0;
listData = NULL;
}
bool UnsortedType::IsFull() const
{
NodeType* location;
try
{
location = new NodeType;
delete location;
return false;
}
catch(std::bad_alloc excecption)
{
return true;
}
}
int UnsortedType::GetLength() const
{
return length;
}
void UnsortedType::MakeEmpty()
{
NodeType* tempPtr;
while(listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
length = 0;
}
ItemType UnsortedType::GetItem(ItemType item, bool& found)
{
bool moreToSearch;
NodeType* location;
location = listData;
found = false;
moreToSearch = (location != NULL);
while (moreToSearch && !found)
{
switch (item.ComparedTo(info[location])) // this is where the error occurs
{
case LESS :
case GREATER: location = location->next;
moreToSearch = (location != NULL);
break;
case EQUAL: found = true;
item = location->info;
break;
}
}
return item;
}
void UnsortedType::DeleteItem(ItemType item)
{
NodeType* location = listData;
NodeType* tempLocation;
if(item == listData->info)
{
tempLocation = location;
listData = listData->next;
}
else
{
while (!(item == (location->next)->info))
{
location = location->next;
tempLocation = location->next;
location->next = (location->next)->next;
}
}
delete tempLocation;
length--;
}
void UnsortedType::ResetList ()
{
currentPos = NULL;
}
ItemType UnsortedType::GetNextItem()
{
if (currentPos == NULL)
currentPos = listData;
else
currentPos = currentPos->next;
return currentPos->info;
}
//error messages
documents\visual studio 2008\projects\program2\unsortedtype.cpp(81) : error C2065: 'info' : undeclared identifier documents\visual studio 2008\projects\program2\unsortedtype.cpp(102) : error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'ItemType' 1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(90) : see declaration of 'std::operator ==' //This basically keeps repeating for several lines and the last error message before fatal error is below documents\visual studio 2008\projects\program2\unsortedtype.cpp(109) : error C2676: binary '==' : 'ItemType' does not define this operator or a conversion to a type acceptable to the predefined operator
any help would be greatly appreciated
MOD EDIT: Added code tags. When posting code, USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 08 October 2012 - 02:29 PM

New Topic/Question
Reply



MultiQuote




|