Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected Unqualified-Id before 'delete' function

Tags:

c++

I wrote a C++ program, this error appeared and I can not find the cause. Can anybody help me. This function is used to delete element i-th from a linked list, even tried my best but I can't find the reason.

#include <cstdio>
#include <fstream>

using namespace std;

struct node
{
    int value;
    node * next;
};

typedef struct node list;

list* head = NULL;
int list_length = 0;

bool empty(){
    return (head == NULL);
}

void delete(int i){
    if(i>list_length) return;
    if(empty()) return;

    int count = 0;
    list* curr = head;
    while(curr != NULL && count < i-1){
        curr = curr -> next;
        count++;
    }
    list* temp = curr -> next;
    curr next = temp -> next;
    list_length--;
}

int main(){
}
like image 732
Hà Link Avatar asked Dec 09 '22 12:12

Hà Link


2 Answers

You have a method called delete but delete is a keyword in C++.

like image 144
Andrew White Avatar answered Dec 20 '22 16:12

Andrew White


delete is a reserved keyword in C++. You have to rename your function.

like image 20
awesoon Avatar answered Dec 20 '22 16:12

awesoon