I keep getting this error -
error C2819: type 'List' does not have an overloaded member 'operator ->'
i can't figure out why? help?
Main.cpp -
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
#include "List.h"
#include "Node.h"
The error happens here:
void PrintList ( List list ) {
Node * temp = list.getFirst();
Node * temp2 = list->getLast();
while ( temp->getItemName() != temp2->getName() ) {
cout << temp.getItemName() << endl;
}
}
List.h -
#ifndef LIST_H
#define LIST_H
#include "Node.h"
class List
{
private:
Node * First;
Node * Last;
int num_in_list;
public:
List () { num_in_list = 0; First = NULL; Last = NULL; }
int get_num_in_list() { return num_in_list; }
Node * getFirst() { return First; }
Node * getLast() { return Last; }
void del_frnt ();
void push_front (Node *);
void push_back (Node *);
void del_last ();
void add (Node*);
Node * pop_back ();
Node * pop_front ();
int search_item_list (string);
Node * get (int);
};
#endif
List.cpp -
#include <iostream>
#include <string>
#include <cassert>
#include "Node.h"
#include "List.h"
using namespace std;
Node * List:: get ( int position_of_node ) {
assert ( First != NULL);
Node * temp = First;
for (int i = 1; i < position_of_node; i++)
{ temp = temp->getNext(); }
return temp;
}
int List:: search_item_list (string item_searching_for ) {
assert (First != NULL && num_in_list != 0);
int counter = 1;
Node * temp = First;
while ( temp->getItemName() != item_searching_for || temp->getNext() == NULL )
{ temp = temp->getNext(); counter++; }
return counter;
}
void List:: add (Node * node_to_be_added) {
if (num_in_list == 0) { First = node_to_be_added; Last = node_to_be_added; }
else if (num_in_list != 0 ) {
Last->setNext(node_to_be_added);
node_to_be_added->setPrevous(Last);
Last = node_to_be_added;
}
num_in_list++;
}
Node * List :: pop_back ( ) {
assert (Last != NULL);
if ( num_in_list > 1) {
Node * temp = Last;
Last = Last->getPrevous();
Last->setNext(NULL);
temp->setNext(NULL);
temp->setPrevous(NULL);
return temp;
}
else if ( num_in_list == 1 ) {
Node * temp = First;
First = NULL;
return temp;
}
else return NULL;
}
Node * List:: pop_front ( ) {
assert ( First != NULL && num_in_list > 0);
if ( num_in_list > 1 ) {
Node * temp = First;
First = First->getNext();
First->setPrevous(NULL);
temp->setNext(NULL);
temp->setPrevous(NULL);
return temp;
}
else if ( num_in_list == 1) {
Node * temp = First;
First = NULL;
return temp;
}
else return NULL;
}
void List:: del_last ( ) {
assert ( Last != NULL );
if ( num_in_list > 1) {
Node * temp_node = Last->getPrevous();
Node * new_last = Last;
temp_node->setNext(NULL);
delete new_last;
num_in_list--;
}
else if ( num_in_list == 1) {
Node * temp = First;
delete temp;
num_in_list = 0;
First = NULL;
}
}
void List:: del_frnt ( ) {
assert ( First != NULL);
if ( num_in_list > 1) {
Node * saveFirst = First;
First->getNext()->setPrevous(NULL);
First = First->getNext( );
delete saveFirst;
num_in_list--;
}
else if ( num_in_list == 1 ) {
Node * saveFirst = First;
delete saveFirst;
num_in_list = 0;
First = NULL;
}
}
void List:: push_back (Node * new_node) {
assert ( Last != NULL );
Last->setNext(new_node);
new_node->setPrevous(Last);
Last = new_node;
num_in_list++;
}
void List:: push_front (Node * new_node) {
if ( First != NULL) {
First->setPrevous(new_node);
new_node->setPrevous(NULL);
new_node->setNext(First);
First = new_node;
num_in_list++;
}
else if ( First == NULL ) {
First = new_node;
Last = new_node;
num_in_list = 1;
}
}
Node.h -
#ifndef NODE_H
#define NODE_H
#include <string>
using namespace std;
class Node
{
private:
string ItemName;
string Quantity;
Node * Next;
Node * Prevous;
public:
Node () { ItemName = " "; Quantity = " "; }
void setItemName (string a) { ItemName = a; }
string getItemName () { return ItemName; }
void setQuantity (string a) { Quantity = a; }
string getQuantity () { return Quantity; }
void setNext (Node * a) { *Next = *a; }
Node * getNext () { return Next; }
void setPrevous (Node * a) { *Prevous = *a; }
Node * getPrevous () { return Prevous; }
};
#endif
Note:I know what I'm doing is just a list, but for a collage class I have to do it :) -Any help / pointers / how to do things better would be GREAT!!!