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

  • SEARCH
  • Home
  • 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 6779365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:22:36+00:00 2026-05-26T16:22:36+00:00

i created a linked list : struct Node and List Class and i used

  • 0

i created a linked list : struct Node and List Class and i used it outside with my main method,

#include "Lists.cpp"
#include <cstdlib>
using namespace std;

int main(){


    Lists l = new Lists(1);

    l.add(2);
    l.add(3);
    l.add(4);
    l.add(5);



    system("pause");
    return 0;
        }

but it produces an error that says “invalid conversion from List* to int”. Is my using of outside class right? Im a little confused how I will solve this.

#include <cstdlib>
#include <iostream>

using namespace std;

struct Node{
       int data;
       Node *next;       
       Node(int i){
                data = i;
                next = NULL;
                }

       };

class List{
      Node *head;



      public:
      List(int i){
               head = new Node(i);
      }

      void addToHead(int i){
          Node *temp = new Node(i);
          temp->next = head;
          head = temp;
           }

      void add(int i){
                Node *currNode = head;
                while(currNode!= NULL){
                        if(currNode->next == NULL){
                          currNode->next = new Node(i);
                          break;         
                                }
                         else{
                          currNode = currNode-> next;      
                              }   
                                 }

                }
      void deleteNode(int i){
           Node *currNode = head;
           Node *prevNode = NULL;

           while(currNode!=  NULL){
                             if(currNode->data == i) {
                             if(prevNode== NULL){
                                           head = head->next;
                                           }                  
                              else{
                                   prevNode->next = currNode->next;
                                   }                                
                              }
                              prevNode = currNode;
                              currNode =  currNode -> next;                            
                             }
           }
      void insert(int position, Node *n){
           Node *currNode= head;
           Node *prevNode = NULL;

           for(int counter = 0; counter>= position && currNode!= NULL; counter++){
                   if(counter==position){
                              Node *temp = currNode;
                              n->next  =  currNode;
                              prevNode->next= n;                              
                              }                  
                   prevNode = currNode;
                   currNode = currNode-> next;
                   }
           }
      void traverse(Node *node){
           if(node!=NULL){
           cout<<  node-> data  <<endl;
           traverse(node->next);
                          }
           }

      };
  • 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-05-26T16:22:37+00:00Added an answer on May 26, 2026 at 4:22 pm
    Lists l = new Lists(1);
    

    should be:

    Lists *l = new Lists(1);
    

    new provides a pointer.

    The reason you get that specific error is that the line would be valid if the conversion chain Lists * -> int -> Lists were valid. The second is valid here because of the constructor but the first is not.

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

Sidebar

Related Questions

I create a linked list dynamically and initialize the first node in main(), and
I created a double linked list class, and am trying to use it with
#define STRLEN 65 /*Create linked list */ struct node { char str[STRLEN]; struct node
#include <iostream> using namespace std; struct Term; struct Node; typedef Term* termPtr; typedef Node*
I have the following struct for a linked list: struct Node { int type;
I have a linked list of Nodes, each Node is defined as: struct Node
I created a Linked List, with insert, search and remove functions. I also created
I've already created the Binary Tree and Linked list classes, I'm just in need
I have created a discount in commerce server, and linked it with a list
Please explain what this task is about? Create a generic linked list class that

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.