Results 1 to 7 of 7

Thread: expected : or ; before { token error

  1. #1
    Join Date
    Nov 2012
    Beans
    30

    expected : or ; before { token error

    void enqueue(const string& name, const int age)
    {
    node* newnode = new node(); // at this place
    newnode->set(name, age);
    newnode->setnext(NULL);
    rear->setnext(newnode);
    rear = newnode;
    size++;
    }

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,240
    Distro
    Kubuntu

    Re: expected : or ; before { token error

    Quote Originally Posted by hatsoff View Post
    void enqueue(const string& name, const int age)
    {
    node* newnode = new node(); // at this place
    newnode->set(name, age);
    newnode->setnext(NULL);
    rear->setnext(newnode);
    rear = newnode;
    size++;
    }
    In C++, if a constructor does not take any parameters, you do not specify the braces; otherwise the declaration (albeit in error) appears as if you are attempting to call 'new' on a function.

    Change your statement to be:
    Code:
    node* newnode = new node;
    P.S. Always post code in CODE tags -- so as to preserve code formatting.

  3. #3
    Join Date
    Nov 2012
    Beans
    30

    Re: expected : or ; before { token error

    it did not solve the problem still getting same error.

  4. #4
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,109
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: expected : or ; before { token error

    More context is needed. The error lies outside the fragment you have posted.

  5. #5
    Join Date
    Nov 2012
    Beans
    30

    Re: expected : or ; before { token error

    after changes ,it compiled right away but crashing, when i add name

  6. #6
    Join Date
    Nov 2012
    Beans
    30

    Re: expected : or ; before { token error

    i think there is problem with getline function please see this am i doing right?
    HTML Code:
     do
                {
                    
                    cout << "Enter the name of classmate " << endl;
                    getline(cin, nameofclassmate);
                    cout << "Enter the age " << endl;
                    cin >> ageofclassmate;
                    queue1.enqueue(nameofclassmate, ageofclassmate);
                    cout << "do you want to add more : (y/n)";
                    cin >> input;
                } while (input == 'y' || 'Y');

  7. #7
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,109
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: expected : or ; before { token error

    In the previous thread dwhitney67 wrote
    1. Acquiring raw input from the command line. Don't assume cin will flush input stream of newline characters (ie <Enter> key) that you input. Using getline() is a good choice.

    2. Don't assume user will start adding nodes. Check the validity of your queue's pointers before attempting to access them.
    You need to pay attention to both of these pieces of advice.

    Hint: what is the value of rear when you first do this?
    Code:
    rear->setnext(newnode);
    Note that this loop runs forever:
    Code:
    do {
    }
    while (input == 'y' || 'Y');
    I'm sure that there are many more mistakes, but you need to do your own homework.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •