Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:24:21+00:00 2026-06-14T13:24:21+00:00

I am writing a C++ linked list class. I have implemented and tested insert

  • 0

I am writing a C++ linked list class. I have implemented and tested insert and print. However, I can’t seem to return a Node pointer for delete. I get these errors when I try delete:

    Node.h:11: error: expected unqualified-id before "delete"
    Node.h:11: error: abstract declarator `Node*' used as declaration
    Node.h:11: error: expected `;' before "delete"

    Node.cpp:21: error: expected unqualified-id before "delete"
    Node.cpp:21: error: expected init-declarator before "delete"
    Node.cpp:21: error: expected `,' or `;' before "delete"

    make.exe: *** [Node.o] Error 1

    Execution terminated

Here’s my code:

Node.h

    #ifndef Node_H
    #define Node_H


    class Node{
          int data;
          Node* next;

    public:
           Node(int data);       
           void insert(int d);
           Node* delete(int d);
           void printOut(void);
    };

    #endif

Node.cpp

    #include <stdio.h>
    #include "Node.h"

    Node::Node(int d){
          data = d;
          next = NULL;
          }

    void Node::insert(int d){

          Node* n = this;
          Node* current = new Node(d);

          while(n->next != NULL){
                  n = n->next;                   
                  }

          n->next = current;
          }

    Node* Node::delete(int d){

          Node* head = this;
          Node* n = this;

          if (n->data = null){
             return n;
             }

          if (n->data == d){
             return n->next;
             }

          while(n->next != NULL){

          if (n->next->data == d){
             n->next = n->next->next;
             return head;
             }

          n = n->next;

          }

        return head;

        }

    void Node::printOut(void){

         Node* n = this;

         while(n->next != NULL){
                      printf("%d ->", n->data);
                       n = n->next;                   
                       }

         printf("%d \n", n->data);

         }

main:

    #include <iostream>
    #include <stdio.h>
    #include <cstdlib>

    #include "Node.h"
    using namespace std;

    int main (void){
        int i = 0;

        Node* root = new Node(111);
        Node* result;

        for (i = 0; i < 9; i++){
            root->insert(i);
            } 

        root->printOut();

        result = root->delete(5);

        result->printOut();

        printf("Hello j \n");

        getchar();
        delete[] root; 
        return 0;   
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:24:22+00:00Added an answer on June 14, 2026 at 1:24 pm

    The token delete is a reserved keyword in C++. Pick a different name for the function (like remove).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am writing a linked list data type. I have an inner class
I am writing a a linked list and I have an Iterator class within
For a CS class I am writing a linked list implementation of a linked
I'm writing a linked list and I want a struct's destructor (a Node struct)
I am currently writing stack that is being implemented with a linked list. I
I'm writing an immutable linked list class in C, but one method is mysteriously
I'm attempting to create a PriorityQueue class in Java implemented via a Linked List.
I'm writing a simple linked list based memory manager in the form: ...Header|Block|Header|Block... with
I'm writing a simple linear linked list implementation in PHP. This is basically just
I was writing two implementations of a Linked List for an assignment, a Doubly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.