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

Discussion in 'C++' started by sandy@murdocks.on.ca, Oct 5, 2006.

  1. Guest

    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>
    , Oct 5, 2006
    #1
    1. Advertising

  2. Larry Smith Guest

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

    };
    Larry Smith, Oct 5, 2006
    #2
    1. Advertising

  3. Alvin Guest

    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
    Alvin, Oct 5, 2006
    #3
  4. Salt_Peter Guest

    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>
    Salt_Peter, Oct 5, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bubzilla
    Replies:
    2
    Views:
    923
    bubzilla
    Sep 25, 2006
  2. andrew browning
    Replies:
    16
    Views:
    15,476
    Artie Gold
    Mar 13, 2006
  3. Thomas Barth
    Replies:
    3
    Views:
    12,739
    Thomas Barth
    Jul 18, 2006
  4. Damien
    Replies:
    5
    Views:
    14,693
    Damien
    Dec 13, 2006
  5. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    This is an unexpected token. The expected token is 'NAME'

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Jul 13, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    775
    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=
    Jul 13, 2007
Loading...

Share This Page