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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:03:51+00:00 2026-05-12T10:03:51+00:00

Trying to figure out why my list() class pointers are being overwritten with the

  • 0

Trying to figure out why my list() class pointers are being overwritten with the third node. What happens in the insert function (below) is that the third time the insert function is called my headByName->nextByName node pointer is overwritten by the third node, when it should point to the second. So as you can guess the 4th node is overwritten by the 5th and the 6th node is overwritten by the 7th, hence the “jump” in nodes.

The attributes of the winery object are passed through the winery ctor and then to the list::insert function via these calls in main:

//main.cpp
//the attributes of the winery object are the paramaters, name, location, acres, rating:
list *listPtr = new list();
wineries->insert(winery("Lopez Island Vinyard", "San Juan Islands", 7, 95));
wineries->insert(winery("Gallo", "Napa Valley", 200, 25));
wineries->insert(winery("Cooper Mountain", "Willamette Valley", 100, 47));

Then the winery ctor is called where I allocate the private pointer memembers:

//winery.cpp
winery::winery(const char * const name, const char * const location, const int acres, const int rating)
  : m_acres( acres ), m_rating( rating )
{
    if (name)
    {
        size_t len = strlen( name ) +1;
        m_name = new char[len];
        strcpy_s( m_name, len, name );
    }
    else
        m_name = NULL;

    if (location)
    {
        size_t len = strlen( location ) +1;
        m_location = new char[len];
        strcpy_s( m_location, len, location );
    }
    else
        m_location = NULL;
}

And then to the issue at hand: If you can imagine this function has already been called twice then current_node will have the thrid winery. headByName will have the first node and in it [+], headByName->next will have the third. I need headByName->next to have the second. I am just wondering why it has been overwritten..

// list.cpp
void list::insert(const winery& winery)
{
    node *current_node  = new node( winery ); // the third wineries info!
    node *next_node     = NULL;
    list *list_ptr      = NULL;
    do
    {
        if ( headByName == NULL || headByRating == NULL ) // then we are here for the first item
        {   
            headByName   = current_node; // the list ptrs have a node address. 
            headByRating = current_node;
        } 
        else
        {           

            next_node                  = current_node; 
// transfer by the next call in main.
            headByName->nextByName     = next_node;
            headByRating->nextByRating = next_node;

        }
    } while ( headByName == NULL || headByRating == NULL );

    next_node    = NULL;
    current_node = NULL;
}

Could someone please find my second node?
oh yeah, and the pointers that are available to me:

struct node
{
    winery  item;
    node *  nextByName;
    node *  nextByRating;
};

class list
{
    ...
private:
    node * headByName;
    node * headByRating;
};

this might be of some importance, its the body of the node ctor:

//list.cpp
list::node::node(const winery &winery) :
nextByName( NULL ), nextByRating( NULL ), item( winery.getName(),
winery.getLocation(), winery.getAcres(), winery.getRating() )
{
    // where the item paramters are all pub-mem functions of the winery class.  

}
  • 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-12T10:03:51+00:00Added an answer on May 12, 2026 at 10:03 am

    I think that problem is here:

    headByName->nextByName     = next_node;
    headByRating->nextByRating = next_node;
    

    You’re always override second node. As I understand you should find last one by iterating through whole list and insert after last node.

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

Sidebar

Ask A Question

Stats

  • Questions 170k
  • Answers 171k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $("#mydiv a").removeClass("active"); May 12, 2026 at 2:12 pm
  • Editorial Team
    Editorial Team added an answer Your CSV may be using Carriage Returns instead of Newlines,… May 12, 2026 at 2:12 pm
  • Editorial Team
    Editorial Team added an answer You could try something like what they have at http://loadimpact.com/… May 12, 2026 at 2:12 pm

Related Questions

I'm trying to figure out an architecture for plugins, but I've never worked with
I am writing some class and it wont compile without using System.Linq. But i
I'm having a hard time trying to figure this out. Say I have the
So i'm toying around with stackless python, writing a very simple webserver to teach

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.