Iterators, need help.

I keep getting this error and I dont know why.
Line 107: Just before my main.
[Error] cast from 'NodeType*' to 'unsigned int' loses precision [-fpermissive]

I also need to add statements to ListType that will display the address of the start pointer, the address pointed by next, the data contents of the node pointed to by next and the link pointer value in node pointed to by next. I do not know how to do this.

I know the statements should look something like (unsigned int)start, but that leads me back to the same error I am already getting in earlier code.

#include <cstdlib>
#include <iostream>
using namespace std;
#include <string>

class NodeType {
public:
string NodeValue;
NodeType *link;
};

class ListType {
NodeType *next, *last, *start;

public:
ListType() { start = NULL; }
void buildList(void);
void printList(void);
NodeType *searchList(string);
void deleteVal(NodeType *);
void addValToEnd(string);


};

NodeType *ListType::searchList(string who)
{
next = start;
while(next != NULL)
{
if(next->NodeValue == who)
return next;
else
{
next = next->link;
}
}
return next;
}

void ListType::deleteVal( NodeType *p)
{
bool Deleted = false;
if(p == start)
{
last = start;
start = start->link;
delete last;
}
else
{
last = start; next = start->link;
while(!Deleted)
{
if(next == p)
{
last->link = next->link;
delete next;
Deleted = true;
}
else
{
last = next;
next = next->link;
}
}
}
}

void ListType::buildList(void)
{
string name;
cout << "\n\nEnter a name or xxx to goto Part 2: ";
cin >> name;
while(name != "xxx")
{
if(start == NULL)
{
start = new NodeType;
start->NodeValue = name;
start->link = NULL;
last = start;
}
else
{
next = new NodeType;
next->NodeValue = name;
next->link = NULL;
last->link = next;
last = next;
}
cout << "\n\nEnter a name or xxx to goto Part 2: ";
cin >> name;
}
};

void ListType::printList(void)
{

if(start == NULL)
cout << "\n\nCurrent List contents: List is empty\n\n";

else {

for( unsigned int i = 0; i < 32 ; ++i )
cout << "\n\nCurrent contents of list:\n\n";
cout<< (unsigned int)start;
next = start;
while (next != NULL)
{
cout << next->NodeValue << "\n";
next = next->link;
}
}
}

int main(int argc, char *argv[])
{
bool notDone = true;
ListType aList;
string person, resp;
aList.buildList();
NodeType *loc;
cout << "\n\nPress any key and <Enter> to print list:\n\n";

while(notDone)
{
aList.printList();
cout << "\n\nPart II: Enter a name to search for or q to quit: ";
cin >> person;
if(person != "q")
{
loc = aList.searchList(person);
if(loc == NULL)
cout << "\n\n " << person << " is not in the list\n\n";
else
{
// cout << "\n\n" << person << " in list at location = " << (unsigned int)loc << "\n\n";
cout << "Type <y> to delete " << person << " from the list, <n> not to delete\n\n";
cin >> resp;
if(resp == "y")
aList.deleteVal(loc);
}
}
else notDone = false;
}

system("PAUSE");
return EXIT_SUCCESS;
}
Last edited on
Please use code tags like the one the Beginner forum provides, and please give us line numbers for your error.

-Albatross
My apologies, I will repost. I am just in a rush.
Topic archived. No new replies allowed.