473,378 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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(ListType *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(ListType *list);

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

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

************************************************** ****************************/
void CreateList(ListType *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(int 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(thisList);
}

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

Inputs:
Outputs: None
Notes: Creates an empty linked list with no nodes
************************************************** ****************************/
void JobCollection::CreateList(ListType *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(ListType *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(ListType *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\COSC202H\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 5746
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(ListType *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(ListType *list);

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

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

************************************************** ****************************/
void CreateList(ListType *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(int 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(thisList);
}

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

Inputs:
Outputs: None
Notes: Creates an empty linked list with no nodes
************************************************** ****************************/
void JobCollection::CreateList(ListType *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(ListType *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(ListType *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\COSC202H\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(int 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\COSC202H\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::MyStruct MyClass::MyFunction() {
//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
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...
1
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...
2
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...
13
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...
22
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;...
3
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...
4
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,...
4
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.