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 8926245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:55:22+00:00 2026-06-15T07:55:22+00:00

I am trying to store a customer in a linked list. I am new

  • 0

I am trying to store a customer in a linked list. I am new to C++ so I have tried to adapt a int linked list to a Customer linked list. This is my code for the customer and list and the main running of it. The errors I get are:

1>c:\users\tashiemoto\desktop\c++\assignmentfinal\assignmentfinal\main4.cpp(12): error C2182: ‘addToList’ : illegal use of type ‘void’
1>c:\users\tashiemoto\desktop\c++\assignmentfinal\assignmentfinal\main4.cpp(12): error C2440: ‘initializing’ : cannot convert from ‘Customer *’ to ‘int’

Which happens when I try and add a new data entry to the linked list on main.cpp. I always have a red line under addtoList on main. I think it has something to do with customer but I’m not sure.

Main.cpp

#include <iostream>
#include "customer.h"
#include "list.h"

void main ()

{
    //construction
    LinkedList();

    //add a new node to the last
    void addToList( new Customer("hhht","hhh","hhh","hhhkjk","klio"));

}

list.h

#include "customer.h"

//forward declaration
class Node;

//class definition
class LinkedList
{
public:
    //construction
    LinkedList();

    //add a new node to the last
    void addToList(Customer *data);

    //find an element in list and set current pointer
    void find( int key);

    //get data from element pointed at by current pointer
    Customer* getCurrent(void);

    //delete element pointed at by current pointer
    void deleteCurrent(void);

private:
    //data members
    Node *_begin;       //pointer to first element in list
    Node *_end;     //pointer to last element in list
    Node *_current; //pointer to current element in list
};

list.cpp

LinkedList::LinkedList()
{
    //initialise node pointers
    _begin = NULL;
    _end = NULL;
    _current = NULL;
}

void LinkedList::addToList(Customer *data)
{
    Node *newNodePtr;

    //craete new instance of Node
    newNodePtr = new Node;

    //set data
    newNodePtr->setData(data);

    //check if list is empty
    if( _begin == NULL) 
    {
        _begin = newNodePtr;
    }
    else
    {
        newNodePtr->setPrevNode(_end);
        _end->setNextNode(newNodePtr);
    }

    //set current pointer end end pointer
    _end = newNodePtr;
    _current = newNodePtr;
}

Customer.h

   #include <iostream>
   #include<string>

   using namespace std;

   class Customer
   {
       private:
         //
         // class members
         //
         string name; 
         string address;
         string telephone;   
         string sex;
         string dob;

       public:

         // Constructor
         Customer(string init_name, string init_address, string init_telephone, string init_sex, string init_dob);   
         // a print method
         void showPersonDetails(void);

         // This operator is a friend of the class, but is NOT a member of the // class:
         friend ostream& operator <<(ostream& s, Customer& a);

   };  

   // This is the prototype for the overload
    ostream& operator <<(ostream& s, Customer& a);

   #endif

and customer.cpp

#include "customer.h"

using namespace std;


Customer::Customer(string init_name, string init_address, string init_telephone, string init_sex, string init_dob)
{
    name = init_name;
    address = init_address;
    telephone = init_telephone;
    sex = init_sex;
    dob = init_dob;
}

ostream& operator <<(ostream& s, Customer& a)
{
        s << "Name : "         << a.name << endl;
        s << "Address : "      << a.address << endl ;
        s << "Telephone : "    << a.telephone << endl;
        s << "Sex : "          << a.sex << endl ;
        s << "Date of Birth : "<< a.dob << endl;
        return s;
}
  • 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-15T07:55:24+00:00Added an answer on June 15, 2026 at 7:55 am

    The problems appear to be relatively easy to address:

    void main ()
    
    {
        // This is wrong, it constructs an unnamed temporary.
        //construction
        // LinkedList();
    
        // This is how you default construct a LinkedList item
        LinkedList myList;
    
        // This is wrong, you don't use the full signaure when calling a function
        //add a new node to the last
        // void addToList( new Customer("hhht","hhh","hhh","hhhkjk","klio"));
    
        // This calls the addToList member function of the myList object
        myList.addToList(new Customer(...));
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that needs to store customer data which I'm trying to
For two days I have been trying to add new customer attribute to the
Im trying to store a list,collection of data objects in Hbase. For example ,a
I'm trying to store the size of a queue in an int in C++.
I'm trying to store a List as a DynamoDB attribute but I need to
I'm trying to match subdomains to a customer id in symfony. i.e. i have
i'm trying to add an attribute to customer model. it a select list which
I am trying to add Google Trust Badge to my magento store. I tried
I'm trying to figure out what to do here. I have customer data in
I am running a Magento Store and have created a seperate login outside of

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.