cooper
cooper

Reputation: 315

expected unqualified-id before bool function?

I am writing a simple (very simple) linked list to brush up on my programming skills, but apparently, I'm failing since I got this compiler error and I can't figure out what's wrong. The problem is with the delete function:

bool delete(node* head, node* delMe){
    node* current;

    if(delMe == head){
            if(head->next != NULL){
                    head = delMe->next;
                    free(delMe);
            }else{
                    head = NULL;
                    cout<<"There are no more elements in the LL"<<endl;
            }
            return true;
    }else{
            current = head;
            while(current){
                    if(current->next == delMe){
                            current->next = delMe->next;
                            free(delMe);
                            return true;
                    }
                    current = current->next;
            }

    }
    return false;
    }

I get expected unqualified-id before 'delete'.

I thought it might be something with the insert function above it, but when I comment out the delete function altogether, the program compiles without problems.

Upvotes: 1

Views: 2257

Answers (1)

Nikos C.
Nikos C.

Reputation: 51920

delete is a keyword in C++. You cannot use it as an identifier.

Upvotes: 1

Related Questions