0

Unable to recognize the error in creating a linked list insertion function in linked list class the compiler giving this " error: qualified-id in declaration before '(' token But it seems like all the parenthesis are placed correctly.

    #include <iostream>

using namespace std;
    void additem();
    void deleteitem();
    void searchitem(int x);

struct student{
int data;
int * next;
};

   student * head;
   student * curr;

int main()
{
   int x;
   cout << "To add item type 1" << endl;
   cin >> x;

   switch(x)
   {
     case 1:
     additem();
   }

    return 0;
}


void additem()
{
    student * temp;

    if(head == NULL)
    {
        temp = new student;
        head = temp;
        curr = temp;
        temp->next = NULL;
        cout << "Enter data" << endl;
        cin >> temp->data << endl;
    }

    else if(head != NULL)
    {
         temp = new student;
         curr->next = temp;
         curr = temp;
         temp->next = NULL;
         cout << "Enter data" << endl;
         cin >> temp->data ;
    }
    else{
        break;
    }

}

1 Answer 1

1

You're declaring a class and methods within main. This is not allowed (nested functions). linkedlist::additem needs to be defined before main.

Sign up to request clarification or add additional context in comments.

1 Comment

@MAhmadRana What does your code look like now, and where exactly are you getting the error in it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.