Student requests help... expected `;' before '(' token

S

sandy

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

The first error makes no sense to me since it is OBVIOUS I set it to
return void (nothing). The second seems to imply that one of the lines
above is missing a ;

If I comment out the 'void ClearList...' the ; error goes away and it
will compile. This indicates that I am NOT missing a ; before the
declaration.

Can anyone wiser than me see the problem?? I have been looking at that
one line for an hour.

<code>
class JobCollection
{
public:

/******************************************************
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);


typedef Job ListEntry;

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

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


private:

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

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

******************************************************************************/
void CreateList(ListType *list);

};
</code>
 
L

Larry Smith

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

The first error makes no sense to me since it is OBVIOUS I set it to
return void (nothing). The second seems to imply that one of the lines
above is missing a ;

If I comment out the 'void ClearList...' the ; error goes away and it
will compile. This indicates that I am NOT missing a ; before the
declaration.

Can anyone wiser than me see the problem?? I have been looking at that
one line for an hour.

<code>
class JobCollection
{
public:

/******************************************************
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);


typedef Job ListEntry;

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

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


private:

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

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

******************************************************************************/
void CreateList(ListType *list);

};
</code>

class Job
{
/* contents of 'Job' ... */
};

class JobCollection
{
public:

JobCollection();

/* typedefs for structs are not req'd in C++ */
struct ListNode
{
/* Warning: 'Job' must have already been defined */
Job data;
JobCollection::ListNode * pNext;
};

struct ListType
{
int count;
JobCollection::ListNode * pHead;
};

void ClearList(JobCollection::ListType * pList);

private:

void CreateList(JobCollection::ListType * pList);

};
 
A

Alvin

void ClearList(ListType *list);


typedef Job ListEntry;

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

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

ListType is declared _after_ the declaration for ClearList(). Therefore, the
compiler doesn't know about it when it is looking at ClearList(). Notice
how you are not getting the error for CreateList()? Putting the typedef for
ListType before the ClearList() declaration will correct the error.

Alvin
 
S

Salt_Peter

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

The first error makes no sense to me since it is OBVIOUS I set it to
return void (nothing). The second seems to imply that one of the lines
above is missing a ;

If I comment out the 'void ClearList...' the ; error goes away and it
will compile. This indicates that I am NOT missing a ; before the
declaration.

Can anyone wiser than me see the problem?? I have been looking at that
one line for an hour.

Your compiler is your friend, its telling you that that it recognizes
ClearList and a return type but that its unable to match a declaration
with whatever is between the parantheses (read between the lines).
ListType at that point was never declared. So the compiler proceeds by
ignoring everything else on that line. That ignoring is your hint to
the solution.

There is no requirement for the compiler to detect that ListType is an
undeclared variable, function or pointer or anything at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top