#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    132
    Rep Power
    2

    Type could not be resolved... (C++)


    Hi guys.

    I'm trying to create a simple linked list class.
    This is what I have so far:

    this is the header file:
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    
    class LinkedList
    {
    private:
    	class Node
    	{
    	public:
    		Node* next;
    		Node* prev;
    		string aString;
    	};
    	Node* head;
    	Node* tail;
    public:
    	LinkedList();
    	~LinkedList();
    	void InsertNode(const string str);
    	void DeleteNode(const string str);
    	Node* FindNode(const string str);
    };
    the problem is with the implementation of Node* FindNode(const string str);.

    this is the source file (scroll to the bottom):
    Code:
    #include"func.h"
    
    LinkedList::LinkedList()
    {
    	cout<<"Constructor called"<<endl;
    	head=NULL;
    	tail=NULL;
    }
    
    
    LinkedList::~LinkedList()
    {
    	cout<<"Destructor called"<<endl;
    
    	while (head!=tail)
    	{
    		head=head->next;
    		delete head->prev;
    	}
    
    	delete head;
    }
    
    
    void LinkedList::InsertNode(const string str)
    {
    	Node* newNode=new Node;
    	newNode->aString=str;
    	newNode->next=NULL;
    
    	if (head)
    	{
    		newNode->prev=tail;
    		tail->next=newNode;
    		tail=newNode;
    	}
    	else
    	{
    		head=newNode;
    		tail=newNode;
    		newNode->prev=NULL;
    	}
    }
    
    
    void LinkedList::DeleteNode(const string str)
    {
    	Node* conductor=head;
    
    	while (conductor)
    	{
    		if (conductor->aString==str)
    		{
    			conductor->prev->next=conductor->next;
    			conductor->next->prev=conductor->prev;
    			delete conductor;
    			return;
    		}
    	}
    }
    
    
    Node* LinkedList::FindNode(const string str) //Type "Node" could not be resolved
    {
    
    }
    why?
    how is it that I used this type without any problems in other methods, but here suddenly it couldn't be resolved?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Node is private and you tried to look for it outside of a private space. My c++ posts are essentially worthless, I'm just tagging onto this thread.

    I also think your DeleteNode method has a terrible flaw. If the condition is false
    if (conductor->aString==str)
    the program doesn't change the value of conductor and will run until your cpu melts at around 3000 degrees Rankine.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    132
    Rep Power
    2
    Originally Posted by b49P23TIvg
    Node is private and you tried to look for it outside of a private space. My c++ posts are essentially worthless, I'm just tagging onto this thread.
    I see...
    OK, thanks for the help.
    I'll try to do it differently.

    Originally Posted by b49P23TIvg
    I also think your DeleteNode method has a terrible flaw. If the condition is false
    if (conductor->aString==str)
    the program doesn't change the value of conductor and will run until your cpu melts at around 3000 degrees Rankine.
    yeah, I know.
    I fixed it right after I posted this thread.

IMN logo majestic logo threadwatch logo seochat tools logo