473,834 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Student looking for more help. `ListNode' does not name a type

I am creating a class (or so I hope) which is to be a JobCollection,
linked list of 'Job'. Job is another class already created.
JobCollection is just the linked list manager.

I have to have this separated into a .h and .cpp file. The code I am
attempting to put into the class is code that I have used before, but
simply put into the same file/class with the rest of the application.

My header looks like this:
<code>
#ifndef JobCollection_h
#define JobCollection_h

#include "Job.h"
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;
class JobCollection
{
public:
typedef Job ListEntry;

typedef struct list_node_def
{
ListEntry data;
struct list_node_def *next;
}ListNode;

typedef struct listtype
{
int count;
ListNode *head;
}ListType;
/*************** *************** *************** *********
Constructor

Inputs:
Outputs:

Notes: Creates a new empty linked list with no nodes.
*************** *************** *************** ***************/
JobCollection() ;


/*************** *************** *************** *************** *************** ***
ClearList

Inputs: Pointer to a list
Outputs: None

Notes: Empties the list of all nodes.

*************** *************** *************** *************** *************** ****/
void ClearList(ListT ype *list);

/*************** *************** *************** *************** *************** *****
CheckListEmpty

Inputs: Pointer to a list
Outputs: boolean - True = Empty

*************** *************** *************** *************** *************** *****/
bool CheckListEmpty( ListType *list);

/*************** *************** *************** *************** *************** ******
ListSize

Inputs: pointer to a List
Outputs: Number of elements in the list

*************** *************** *************** *************** *************** ******/
int ListSize(ListTy pe *list);

/*************** *************** *************** *************** *************** ***
CreateList

Inputs:
Outputs: None
Notes: Creates an empty linked list with no nodes

*************** *************** *************** *************** *************** ***/
void CreateList(List Type *list);

/*************** *************** *************** *************** *************** *****
SetPosition

Inputs: pos - position within the list to move to, *list
pointer
Outputs: ListNode

Notes: Move the pointer to a specific node in the list, by
position

*************** *************** *************** *************** *************** ****/
ListNode *SetPosition(in t pos, ListType *list);
private:
};
#endif

</code>

my .cpp file looks like this:

<code>
#include "JobCollection. h"
#include "Job.h"
#include <string>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
using namespace std;

/*************** *************** *************** *********
Constructor

Inputs:
Outputs:

Notes: Creates a new empty linked list with no nodes.
*************** *************** *************** ***************/
JobCollection:: JobCollection()
{
ListType *thisList;
CreateList(this List);
}

/*************** *************** *************** *************** *************** ***
CreateList

Inputs:
Outputs: None
Notes: Creates an empty linked list with no nodes
*************** *************** *************** *************** *************** ***/
void JobCollection:: CreateList(List Type *list)
{
/* initialize list to empty*/
list->head = NULL;
list->count = 0;
}

/*************** *************** *************** *************** *************** ***
ClearList

Inputs: Pointer to a list
Outputs: None

Notes: Empties the list of all nodes.
*************** *************** *************** *************** *************** ****/
void JobCollection:: ClearList(ListT ype *list)
{
//re-set list to empty /
ListNode *currptr, *tmpptr;
currptr = list->head;
while(currptr != NULL)
{
tmpptr = currptr;
currptr = currptr->next;
free(tmpptr);
}
list->count = 0;
list->head = NULL;
}
/*************** *************** *************** *************** *************** ******
ListSize

Inputs: pointer to a List
Outputs: Number of elements in the list

*************** *************** *************** *************** *************** ******/
int JobCollection:: ListSize(ListTy pe *list)
{
/* return the number of occupied elements in the list*/
return list->count;
}

/*************** *************** *************** *************** *************** *****
SetPosition

Inputs: pos - position within the list to move to, *list
pointer
Outputs: ListNode

Notes: Move the pointer to a specific node in the list, by
position

*************** *************** *************** *************** *************** ****/
ListNode JobCollection:: SetPosition(int pos, ListType *list)
{
ListNode *currptr;
int counter = 0;

/* make sure pos is within the valid range */
if( (pos < 0) || (pos >= list->count))
{
cout << "*** Error - pos out of range\n";
}
else
{
/*move the pointer forward pos positions*/
currptr = list->head;
while( (counter < pos) && (currptr != NULL))
{
currptr = currptr->next;
counter++;
}
}
if (currptr == NULL)
{
cout << "*** Error - Problem in setPosition\n";
}
else
{
return currptr;
}
}

The error I am getting is:
81 Z:\Trent\COSC20 2H\Assignment1B \JobCollection. cpp `ListNode' does not
name a type

Now in my header I have this snippet:

<code>
typedef struct list_node_def
{
ListEntry data;
struct list_node_def *next;
}ListNode;
</code>

the code CAUSING the error is in the cpp file:
<code>
/*************** *************** *************** *************** *************** *****
SetPosition

Inputs: pos - position within the list to move to, *list
pointer
Outputs: ListNode

Notes: Move the pointer to a specific node in the list, by
position

*************** *************** *************** *************** *************** ****/
ListNode JobCollection:: SetPosition(int pos, ListType *list)
{
ListNode *currptr;
int counter = 0;

/* make sure pos is within the valid range */
if( (pos < 0) || (pos >= list->count))
{
cout << "*** Error - pos out of range\n";
}
else
{
/*move the pointer forward pos positions*/
currptr = list->head;
while( (counter < pos) && (currptr != NULL))
{
currptr = currptr->next;
counter++;
}
}
if (currptr == NULL)
{
cout << "*** Error - Problem in setPosition\n";
}
else
{
return currptr;
}
}
</code>

So, since I have a data type called ListNode in the header file, I
don't understand why the compiler says I don't.

Any help to solve the problem would be appreciated. Help in
understanding WHY would be even MORE appreciated.

Thanks.

Oct 5 '06 #1
6 5783
sa***@murdocks. on.ca wrote:
I am creating a class (or so I hope) which is to be a JobCollection,
linked list of 'Job'. Job is another class already created.
JobCollection is just the linked list manager.

I have to have this separated into a .h and .cpp file. The code I am
attempting to put into the class is code that I have used before, but
simply put into the same file/class with the rest of the application.

My header looks like this:
<code>
#ifndef JobCollection_h
#define JobCollection_h

#include "Job.h"
#include <stdlib.h>
In C++ prefer <cstdlib>, but in any case, it doesn't look like you use
this here.
#include <string>
#include <iostream>
using namespace std;
class JobCollection
{
public:
typedef Job ListEntry;

typedef struct list_node_def
{
ListEntry data;
struct list_node_def *next;
}ListNode;
This is C-style. The simpler C++-style would be:

struct ListNode
{
ListEntry data;
ListNode *next;
};
>
typedef struct listtype
{
int count;
ListNode *head;
}ListType;
/*************** *************** *************** *********
Constructor

Inputs:
Outputs:

Notes: Creates a new empty linked list with no nodes.
*************** *************** *************** ***************/
JobCollection() ;


/*************** *************** *************** *************** *************** ***
ClearList

Inputs: Pointer to a list
Outputs: None

Notes: Empties the list of all nodes.

*************** *************** *************** *************** *************** ****/
void ClearList(ListT ype *list);

/*************** *************** *************** *************** *************** *****
CheckListEmpty

Inputs: Pointer to a list
Outputs: boolean - True = Empty

*************** *************** *************** *************** *************** *****/
bool CheckListEmpty( ListType *list);

/*************** *************** *************** *************** *************** ******
ListSize

Inputs: pointer to a List
Outputs: Number of elements in the list

*************** *************** *************** *************** *************** ******/
int ListSize(ListTy pe *list);

/*************** *************** *************** *************** *************** ***
CreateList

Inputs:
Outputs: None
Notes: Creates an empty linked list with no nodes

*************** *************** *************** *************** *************** ***/
void CreateList(List Type *list);

/*************** *************** *************** *************** *************** *****
SetPosition

Inputs: pos - position within the list to move to, *list
pointer
Outputs: ListNode

Notes: Move the pointer to a specific node in the list, by
position

*************** *************** *************** *************** *************** ****/
ListNode *SetPosition(in t pos, ListType *list);
private:
Extraneous (perhaps left over from some deletions you made for this
post?).
>

};
#endif

</code>

my .cpp file looks like this:

<code>
#include "JobCollection. h"
#include "Job.h"
#include <string>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
<cstdiois preferred.
using namespace std;

/*************** *************** *************** *********
Constructor

Inputs:
Outputs:

Notes: Creates a new empty linked list with no nodes.
*************** *************** *************** ***************/
JobCollection:: JobCollection()
{
ListType *thisList;
CreateList(this List);
}

/*************** *************** *************** *************** *************** ***
CreateList

Inputs:
Outputs: None
Notes: Creates an empty linked list with no nodes
*************** *************** *************** *************** *************** ***/
void JobCollection:: CreateList(List Type *list)
{
/* initialize list to empty*/
list->head = NULL;
list->count = 0;
}

/*************** *************** *************** *************** *************** ***
ClearList

Inputs: Pointer to a list
Outputs: None

Notes: Empties the list of all nodes.
*************** *************** *************** *************** *************** ****/
void JobCollection:: ClearList(ListT ype *list)
{
//re-set list to empty /
ListNode *currptr, *tmpptr;
currptr = list->head;
while(currptr != NULL)
{
tmpptr = currptr;
currptr = currptr->next;
free(tmpptr);
}
list->count = 0;
list->head = NULL;
}
/*************** *************** *************** *************** *************** ******
ListSize

Inputs: pointer to a List
Outputs: Number of elements in the list

*************** *************** *************** *************** *************** ******/
int JobCollection:: ListSize(ListTy pe *list)
{
/* return the number of occupied elements in the list*/
return list->count;
}

/*************** *************** *************** *************** *************** *****
SetPosition

Inputs: pos - position within the list to move to, *list
pointer
Outputs: ListNode

Notes: Move the pointer to a specific node in the list, by
position

*************** *************** *************** *************** *************** ****/
ListNode JobCollection:: SetPosition(int pos, ListType *list)
Your ListNode class is a member of the JobCollection class, and so
outside of that class, you must qualify it:

JobCollection:: ListNode
JobCollection:: SetPosition(int pos, ListType *list)
{
ListNode *currptr;
int counter = 0;

/* make sure pos is within the valid range */
if( (pos < 0) || (pos >= list->count))
{
cout << "*** Error - pos out of range\n";
}
else
{
/*move the pointer forward pos positions*/
currptr = list->head;
while( (counter < pos) && (currptr != NULL))
{
currptr = currptr->next;
counter++;
}
}
if (currptr == NULL)
{
cout << "*** Error - Problem in setPosition\n";
}
else
{
return currptr;
}
}

The error I am getting is:
81 Z:\Trent\COSC20 2H\Assignment1B \JobCollection. cpp `ListNode' does not
name a type
[snip]
So, since I have a data type called ListNode in the header file, I
don't understand why the compiler says I don't.

Any help to solve the problem would be appreciated. Help in
understanding WHY would be even MORE appreciated.
See above.

Cheers! --M

Oct 5 '06 #2
sa***@murdocks. on.ca wrote:
I am creating a class (or so I hope) which is to be a JobCollection,
linked list of 'Job'. Job is another class already created.
JobCollection is just the linked list manager.

I have to have this separated into a .h and .cpp file. The code I am
attempting to put into the class is code that I have used before, but
simply put into the same file/class with the rest of the application.

My header looks like this:
[...]

class JobCollection
{
public:
typedef Job ListEntry;

typedef struct list_node_def
{
ListEntry data;
struct list_node_def *next;
}ListNode;
Why this C construct? Why not do it the C++ way

struct ListNode
{
ListEntry data;
ListEntry *next;
};

???
>
[...irrelevant.. .]

ListNode *SetPosition(in t pos, ListType *list);
private:
};
#endif

</code>

my .cpp file looks like this:

[...irrelevant.. .]
ListNode JobCollection:: SetPosition(int pos, ListType *list)
You need

JobCollection:: ListNode JobCollection:: SetPosition ...

The reason is that in this scope where you are defining the function,
the 'ListNode' *by itself* is not declared. It only exists in its parent
class definition.
{
[...irrelevant.. .]
}

The error I am getting is:
81 Z:\Trent\COSC20 2H\Assignment1B \JobCollection. cpp `ListNode' does
not name a type

[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 5 '06 #3

mlimber wrote:
#include "Job.h"
#include <stdlib.h>

In C++ prefer <cstdlib>, but in any case, it doesn't look like you use
this here.
I have tried to use it but I get an error:
stdlib: No such file or directory.
>
This is C-style. The simpler C++-style would be:

struct ListNode
{
ListEntry data;
ListNode *next;
};
I assume this is a function of cstdlib (which I cannot seem to use...)
private:

Extraneous (perhaps left over from some deletions you made for this
post?).
Extraneous because I am first trying to get it all to work, then I will
worry about what should be private.
>
<cstdiois preferred.
Thanks. I have made that change.
/*************** *************** *************** *************** *************** *****
SetPosition

Inputs: pos - position within the list to move to, *list
pointer
Outputs: ListNode

Notes: Move the pointer to a specific node in the list, by
position

*************** *************** *************** *************** *************** ****/
ListNode JobCollection:: SetPosition(int pos, ListType *list)

Your ListNode class is a member of the JobCollection class, and so
outside of that class, you must qualify it:

JobCollection:: ListNode
JobCollection:: SetPosition(int pos, ListType *list)
Okay, this is where my ignorance shows... Isn't my .cpp file that I am
creating PART of the class?
Any help to solve the problem would be appreciated. Help in
understanding WHY would be even MORE appreciated.

See above.

Cheers! --M
Thanks for your help. It compiles now.

Oct 5 '06 #4
sa***@murdocks. on.ca wrote:
mlimber wrote:
>>#include "Job.h"
#include <stdlib.h>

In C++ prefer <cstdlib>, but in any case, it doesn't look like you
use this here.

I have tried to use it but I get an error:
stdlib: No such file or directory.
Did you miss the 'c' in front of 'stdlib' by any chance?
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 5 '06 #5

sa***@murdocks. on.ca wrote:
mlimber wrote:
#include "Job.h"
#include <stdlib.h>
In C++ prefer <cstdlib>, but in any case, it doesn't look like you use
this here.

I have tried to use it but I get an error:
stdlib: No such file or directory.

This is C-style. The simpler C++-style would be:

struct ListNode
{
ListEntry data;
ListNode *next;
};

I assume this is a function of cstdlib (which I cannot seem to use...)
No, it's not library dependent, just the preferred C++ syntax. Using
the typdef is necessary for a struct definition in C but not in C++.

private:
Extraneous (perhaps left over from some deletions you made for this
post?).

Extraneous because I am first trying to get it all to work, then I will
worry about what should be private.

<cstdiois preferred.

Thanks. I have made that change.
/*************** *************** *************** *************** *************** *****
SetPosition
>
Inputs: pos - position within the list to move to, *list
pointer
Outputs: ListNode
>
Notes: Move the pointer to a specific node in the list, by
position
>
*************** *************** *************** *************** *************** ****/
ListNode JobCollection:: SetPosition(int pos, ListType *list)
Your ListNode class is a member of the JobCollection class, and so
outside of that class, you must qualify it:

JobCollection:: ListNode
JobCollection:: SetPosition(int pos, ListType *list)

Okay, this is where my ignorance shows... Isn't my .cpp file that I am
creating PART of the class?
Doesn't matter if it's in your .cpp or .h file -- you are physically
outside of the block

class MyClass {

};

so for definitions outside of that block you need to use:

MyClass::MyStru ct MyClass::MyFunc tion() {
//definition
}

Any help to solve the problem would be appreciated. Help in
understanding WHY would be even MORE appreciated.
See above.

Cheers! --M

Thanks for your help. It compiles now.
Oct 5 '06 #6
Thank you.

I did miss the 'c'.

When I frustrated I get flustered.

Thanks.

Victor Bazarov wrote:
sa***@murdocks. on.ca wrote:
mlimber wrote:
>#include "Job.h"
#include <stdlib.h>

In C++ prefer <cstdlib>, but in any case, it doesn't look like you
use this here.
I have tried to use it but I get an error:
stdlib: No such file or directory.

Did you miss the 'c' in front of 'stdlib' by any chance?
[..]

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2696
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
1
2028
by: jhon02148 | last post by:
hi this hw have four files: 1. for the main program 2. listp.cpp (the source file) 3. listp.h (the header file) 4. exception.h hi iam done with my hw i still have to do one function which is the last one on program.cpp subsetsum(int aList, int sum)so please can you help.
2
1841
by: sarah | last post by:
I keep getting the following error: g++ SortedList.cpp SortedList.cpp:260: error: expected constructor, destructor, or type conversion before '*' token SortedList.cpp:260: error: expected `,' or `;' before '*' token Line # 260 is ListNode *SortedList::copyList( ListNode *L ) { towards the end of the .cpp file. I have just put stubs in fr the code that I know works for readability purposes. here is my code:
13
4127
by: na1paj | last post by:
here's a simple linked list program. the DeleteNode function is producing an infinit loop i think, but i can't figure out where.. #include <stdio.h> typedef struct { char *str; //str is a dynamic array of characters int length; //number of characters } String;
22
2065
by: Dave Cooke | last post by:
Hi I am very new to C. I am trying to figure out how to initialize a struct in my main program. The struct is declared in anouther header file like this... typedef struct ln { int key; int data; struct ln *next; } listNode, *listNodePtr; just to test in my main method I tried to initialize the
3
34464
by: sandy | last post by:
I am a student who is losing his mind. The code below is a header file which has the line: void ClearList(ListType *list); which generates the following compile time errors: variable or field `ClearList' declared void expected `;' before '(' token
4
1595
by: huiling25 | last post by:
I have a file containing all the customer records. I had a program to read from the file and store using LinkedLists. Each Node is each customer record. Each customer record have AccID, Add, PhoneNum, etc.. All the accID, add are stored in an array. My question is how can I get all the names, ids all printed out? //ListNode.java public class ListNode{ private Object item; private ListNode next,head; public...
4
3428
by: jjh5030 | last post by:
This is a programming assignment. You are asked to work with pointers. Be aware that error messages are often not very helpful when your pointers point to bad locations. Therefore, reserve additional time for debugging. Implement a data structure Extended Queue using pointers. In addition to the usual queue operations Enqueue(x), Dequeue and the trivial operations Make-empty-queue and the Is-empty test, you are asked to have two...
2
2481
by: huiling25 | last post by:
I was given the pseudo code.. but i still cannot figure out how to do it... how can i find if the vertices are adjacent to the vertex on stack top? I know i have to have an array of true/false (to dictate if the vertex is being visited)... dfs(v) { create a stack s to store visited notes s.push(v) while(!s.isEmpty()) { if(no unvisited vertices are adjacent to the vertex on stack top) { //need a...
0
9799
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9649
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10515
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10224
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5629
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4428
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3985
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.