Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Student requests help... expected `;' before '(' token

Reply
Thread Tools

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

 
 
sandy@murdocks.on.ca
Guest
Posts: n/a
 
      10-05-2006
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>

 
Reply With Quote
 
 
 
 
Larry Smith
Guest
Posts: n/a
 
      10-05-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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);

};
 
Reply With Quote
 
 
 
 
Alvin
Guest
Posts: n/a
 
      10-05-2006
(E-Mail Removed) wrote:

> 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
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      10-05-2006

(E-Mail Removed) wrote:
> 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.

>
> <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>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
This is an unexpected token. The expected token is 'NAME' =?Utf-8?B?Y2FzaGRlc2ttYWM=?= ASP .Net 2 07-13-2007 11:38 AM
"expected constructor, destructor, or type conversion before '->' token" using a Singleton Damien C++ 5 12-13-2006 12:39 AM
Header include problems error: expected class-name before '{' token bubzilla C Programming 2 09-25-2006 10:52 AM
expected unqualified-id before "." token? Thomas Barth C++ 3 07-18-2006 01:01 PM
error: expected initializer before '&' token andrew browning C++ 16 03-13-2006 07:55 AM



Advertisments