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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:50:05+00:00 2026-06-09T11:50:05+00:00

This portion of my current assignment has me completely stumped: I am trying to

  • 0

This portion of my current assignment has me completely stumped:

I am trying to build a LinkedList class that includes a copy constructor, which itself calls a static method (*makeCopy()). I cannot figure out how to make the makeCopy method work (all method headers were given to us in the assignment).

class ListNode
{
public:
    ListNode(double v, ListNode *p)
{
   value = v; 
   next = p;
}
private:    
   double value;
   ListNode *next;
   friend class LinkedList;    // LinkedList  has friend status 
};

// The linked list class itself
class LinkedList
{
public:
//Add number to Linked List
void add(double x)
{
    if (head == NULL)
    {
        head = new ListNode(x, NULL);
        return;
    }
    else
    {
        ListNode *nodePtr = head;
        head = new ListNode(x, nodePtr);
    }

}
LinkedList() { head = NULL; }

//Default destructor
~LinkedList()
{
    ListNode *nodePtr = head;
    while (nodePtr != NULL)
    {
        ListNode *garbage = nodePtr;
        nodePtr = nodePtr->next;
        delete garbage;
    }
}

//Copy Constructor
LinkedList(LinkedList &);

//Copy function
static ListNode *makeCopy(ListNode *pList);

private:
   ListNode * head;    

};

Below is how I am trying to write the makeCopy function:

LinkedList::LinkedList(LinkedList &list)
{
    *makeCopy(list.head);
}

static ListNode *makeCopy(ListNode *pList)
{
   if(pList->value == NULL)
   {        
       return NULL;
   }
   else
   {
    ListNode *node = pList;

    while(node != NULL)
    {
        ListNode newOne = *node;
        node = node->next;
    }
}

return;
}

First off I continue to get the error “member ListNode::value is innaccesible.” Second I’m very new to C++ and pretty sure I’m way off. If someone could help nudge me in the right direction it would be greatly appreciated. Thx

This is my current iteration of the copy constructor and the makeCopy method. Unfortunately the ListNode constructor, along with all the method headers, are part of the assignment. We have to write the code for them. The error I’m getting now is this: both return statements say “Error: a constructor or destructor may not return a value.” I’m completely lost on this one since this is just a return statement and I don’t see either a constructor or destructor.

LinkedList::LinkedList(LinkedList &list)
{
    LinkedList *copy = new LinkedList();

    while(list.head != NULL)
    {
        ListNode node = *makeCopy(list.head);
        copy->add(node.value);
        list.head = head->next;
    }

    return *copy;
 }

 ListNode * LinkedList::makeCopy(ListNode *pList)
 {
    ListNode node = *pList;

    return *node;
 }
  • 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-09T11:50:07+00:00Added an answer on June 9, 2026 at 11:50 am
    static ListNode *makeCopy(ListNode *pList)
    

    should be

    ListNode * LinkedList::makeCopy(ListNode *pList)
    

    Your version defines a free function with internal linkeage, and not defines the member.

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

Sidebar

Related Questions

Visit this website. https://zapier.com/ See this portion of the website. I wan that same
I am trying to make a simple alarm. in this code portion a take
I'm trying to install MySQL_python 1.2.2 (I specifically need this version, not the current
Media Browser has a provider model, this is basically a chain of classes that
I am trying to debug a WCF service. This client has been able to
This portion of code checks if a number given (First element in a list)
Could someone explain to me what this portion of code means? repeat scroll 0
following up from yesterday... This portion of the code does work. $(document).ready(function(){ $('#listMenu a').click(function
I'm looking through some code for learning purposes. I'm working through this portion of
With ASP .NET MVC3. In my controller I have this portion of code MasterMindDnetEntities

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.