1 Replies - 1621 Views - Last Post: 07 March 2010 - 07:45 PM Rate Topic: -----

#1 stefaan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 22-November 08

Singly Linked List in C++

Posted 07 March 2010 - 07:13 PM

Im trying to implement a singly linked list for my school project. If i try to add a node in the driver i get an error message that "GetNextPtr" is not a member of ListManager<Node>. GetNextPtr is actually a member in the node classes so i would like to know how to implement ListManager to access the functions in the node class (Whenever i create a ListManager of type Employee or Department). Im using vc++ 2008 express ed, any help would be greatly appreciated.
template <class Node> class ListManager
{
private:
	ListManager <Node> * startPtr;
public:
	ListManager(){ startPtr = NULL;};
	~ListManager();
	unsigned short Menu(unsigned short);
	bool AddNode ();
	bool UpdateNode (Node *Ptr, string key);
	bool ViewNode (Node *Ptr, string key);
	bool DeleteNode (Node *Ptr, string key);
	bool ViewAllNode (Node *Ptr);
};

bool ListManager<Node>::AddNode()
{
	ListManager<Node> * newNode = new ListManager<Node>();	
	ListManager<Node> * currentPtr;	
	if (startPtr == NULL)
		startPtr = newNode;
	else
	{
		currentPtr = startPtr;
		while (currentPtr->GetNextPtr() != NULL)
			currentPtr = currentPtr->GetNextPtr();
		currentPtr = newNode;
	}
	return true;
}

int main ()
{
	ListManager<Employee> *head = new ListManager<Employee>();
	head->AddNode(); //produces an error "GetNextPtr" not a member of ListManager<Node>
        head->Menu(); //Works just fine
	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Singly Linked List in C++

#2 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Singly Linked List in C++

Posted 07 March 2010 - 07:45 PM

Well you can look at my linked list class here -- looking over it might help as I tried to put in many comments.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1