GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Sep-2009, 10:32
foraswim foraswim is offline
New Member
 
Join Date: Sep 2009
Posts: 2
foraswim is on a distinguished road
Smile

The Bag Class with a LinkedList


Hi guys.
I am creating a bag class with a Linkedlist. The aim of the program is to insert a set of words into the LinkedList and for it to return the size and other not important things. I am not sure if i am declaring the LinkedList correctly. there are also two more files node.h and node.cpp, however these have been tested and work
the error i get is
LinkedList.cpp:15: error: ‘LinkedList’ has not been declared
LinkedList.cpp:15: error: expected constructor, destructor, or type conversion before ‘;’ token
LinkedList.cpp:17: error: ‘LinkedList’ has not been declared


The code is
CPP / C++ / C Code:

                                     //MAIN PROGRAM: test.cpp

// Programmer:  Chelsea Putre
// Last modified:  31 August 2009
#include <iostream>
#include <cstdlib>
#include "LinkedList.h"
#include "node.h"

using namespace std;
namespace assign1::LinkedList;

int main()
{
LinkedList list1 = new LinkedList();
	
list1.list_head_insert("The");
list1.list_tail_insert("dog");
list1.list_tail_insert("dog");
list1.list_tail_insert("likes");
list1.list_tail_insert("to");
list1.list_tail_insert("dog");

cout<< list1.size()<< endl;

return 0;
};

                                            //Headerfile: LinkedList.cpp

#include <cassert>
#include <cstdlib>
#include <iostream>
#include "node.h"
#include "LinkedList.h"

using namespace std;
namespace assign
{

LinkedList::LinkedList()
{ 
	head_ptr = NULL, 
	many_nodes = 0;
	}

LinkedList::LinkedList(const LinkedList& source)
	{	
	node *tail_ptr;			//needed for argument of list_copy
	list_copy(source.head_ptr, head_ptr, tail_ptr);
	many_nodes = source.many_nodes;
			}
			
			
LinkedList::~LinkedList()
{
list_clear(head_ptr);
many_nodes = 0
}

size_type LinkedList::count(const value_type& target) const
{
	//counts the number of occurences of a particular string
	size_type answer;
	const node *cursor;
	answer = 0;
	cursor = list_search(head_ptr, target);
	
	while(cursor!=NULL)
	{
		//Each time that cursor is not NULL we add another occurence
		++answer;
		cursor = cursor->get_link();
		cursor = list_search(cursor,target);
	}
	return answer;
}


void LinkedList::list_head_insert(node* head_ptr, const node::value_type entry)
{
	
	list_head_insert(head_ptr,entry);
	++many_nodes;
	
}
void LinkedList::list_tail_insert(node* tail_ptr, const node::value_type& entry)
{
	new_elem = new node();
	new_elem-> set_data(entry);
	new_elem->set_link(NULL);
	tail_ptr->set_link(new_elem);
	tail_ptr = new_elem;
	++many nodes;
	}
void operator +=(const LinkedList& addend)
{
	node *copy_head_ptr;
	node *copy_tail_ptr;

	if (addend.many_nodes > 0)
	{
		list_copy(Addend.head_ptr, copy_head_ptr, copy_tail_ptr);
		copy_tail_ptr->set_link(head_ptr);
		head_ptr = copy_head_ptr;
		many_nodes += addend.many_nodes;
			}	
}
	
}
                                   //CLASS IMPLEMENTATION: LinkedList.h

#ifndef CHELSEA
#define CHELSEA
#include <cstdlib>
#include "node.h"
#include <string>
#include<iostream>

namespace assign1
{

class LinkedList
{

public:

typedef node::value_type value_type;
typedef size_t size_type;

//Constructors
LinkedList();

LinkedList(const LinkedList& source);

//Destructor
~LinkedList();

//Mutating member functions
void  list_head_insert(const value_type& entry) ;//y
void  list_tail_insert(const value_type& entry) ;//y
void operator +=(const LinkedList addend); //y
//void operator =(const LinkedList source);
//Query member functions: Constant member functions
size_type size() const {return many_nodes;}
size_type count(const value_type target) const; //y

private:

size_type many_nodes;
node *head_ptr;
};

LinkedList operator +=(const LinkedList addend);

}
#endif


Any help would be greatly appreciated
  #2  
Old 10-Sep-2009, 11:08
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: The Bag Class with a LinkedList


Quote:
Originally Posted by foraswim
...
LinkedList.cpp:15: error: ‘LinkedList’ has not been declared

Maybe one problem is the namespace inconsistency???

CPP / C++ / C Code:
 //Headerfile: LinkedList.cpp

#include "LinkedList.h"

namespace assign
{

LinkedList::LinkedList()


}

But ...

CPP / C++ / C Code:
//CLASS IMPLEMENTATION: LinkedList.h
namespace assign1 //<--- different namespace???
{

class LinkedList
{

};
}


There are other problems, but this is where I would start.


Regards,

Dave
  #3  
Old 10-Sep-2009, 11:17
foraswim foraswim is offline
New Member
 
Join Date: Sep 2009
Posts: 2
foraswim is on a distinguished road

Re: The Bag Class with a LinkedList


Hi thanks,
I think i did that when i was transferring it into the window. It still has same error. what are the other problems?
cheers
  #4  
Old 10-Sep-2009, 12:46
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: The Bag Class with a LinkedList


Quote:
Originally Posted by foraswim
It still has same error

OK. I will tell you a little story.


Before I post suggestions to try to help other people learn, I try guess what is happening, then I (almost) always try to reproduce the posted problem and see if my suggestion(s) might make a difference.

Since you didn't post node.h, I kludged up a "node" struct so that I could see what a compiler did with the code that you did post.

Then I compiled LinkList.cpp by itself (with g++ -c LinkedList.cpp)


Among other things one message that I got was similar to your error. Namely:
Code:
LinkedList.cpp:13: error: ‘LinkedList’ has not been declared

Now, when I changed the namespace statement in LinkedList.cpp to
CPP / C++ / C Code:
namespace assign1

I did not get that error. (I got lots of others, though.)

Here's the deal: If you are still getting an error about "LinkedList has not been declared", then either

1. You have a problem in your namespace statements as I pointed out in your original post.

or

2. Other parts of the code that you are running are not the same as the code that you posted

or

3. Something in node.h is inconsistent with the code that you posted and/or the code that you are using.

or

4. Some combination of any and/or all of the above

or

5. Something else.


Quote:
Originally Posted by foraswim
. what are the other problems?
I respectfully suggest that if you are getting a message about "LinkedList has not been declared" that there is not much to be gained by guessing what other errors would go away when you fix that one.

"Linked List has not been declared" is a major problem. Find out how to get rid of it. Then go through the remaining errors one at a time. See Footnote.

I also think that chances for getting meaningful help in learning to debug would be improved if you are absolutely sure that the code you post is exactly the same as the code you are using.



Regards,

Dave

Footnote:

"We can face our problem.
We can arrange such facts as we have
with order and method."

Hercule Poirot
--- in Murder on the Orient Express
Last edited by davekw7x : 10-Sep-2009 at 13:47.
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Box Class, need help again :( TransformedBG C++ Forum 7 13-Nov-2006 16:11
C++ class -- Please help vnca_1 C++ Forum 3 14-Jun-2006 13:31
a tester class and then some. postage Java Forum 1 06-May-2006 16:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:08.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.