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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:17:42+00:00 2026-05-31T22:17:42+00:00

struct Node { int value Node* next; } typedef List Node* const Set operator

  • 0
struct Node
{
int value
Node* next;
}
typedef List Node*

const Set operator +(const Set& a, const Set& b)
{
    Set aSet;
    List newList = mergeListsCopy(a.list, b.list);
    aSet.list = newList;
    return aSet;
}

class Set
{
public:
//method decs
private:
    List list;
};

Set::~Set()
{
    list = deleteList(list);    
}

The internals of this code work perfectly fine, mergeListsCopy creates a new list from two singly linked lists and assignes the pointer to the list which is a private variable of aSet.

The problem is when aSet is returned, aSet.list is some strange poison address( in this case 0xf).

When I ran it through the debugger a Set was created in the scope of the operator overload and but two references to this set were also created locally both using the symbol aSet, before the return occurred, the program jumped to the destructor, presumably for the extraneous Set, but since there is only one Set it gets destroyed.

When I comment out my destructor this problem goes away. What did I do wrong?

  • 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-31T22:17:44+00:00Added an answer on May 31, 2026 at 10:17 pm

    You need to follow the Rule of Three.

    If you need to explicitly declare either the destructor, copy constructor or copy assignment operator yourself, you probably need to explicitly declare all three of them.

    It is most likely that temporary nameless objects get created(by calling the implicit compiler generated copy constructor) during the course of execution of your program and when those temporary objects get destroyed by call to destructor it ends up messing your linked list.

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

Sidebar

Related Questions

// Variables typedef struct node { int value; struct node *next; }mynode; // Globals
struct node { node(int _value, node* _next) : value(_value), next(_next) {} int value; node*
typedef struct vertex{ int num; struct vertex *next; } Vertex; Vertex *adj[1]; void buildList(){
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
I've got a node struct struct Node{CString text, int id;}; in a sorted vector.
Having construction in a form: struct Node { Node():left_(nullptr), right_(nullptr) { } int id_;
A link is a pointer to a node typedef struct node * link; In
struct Record_node* Sequential_search(struct Record_node *List, int target) { struct Record_node *cur; cur = List->head
I have a list in C that is something like this: typedef struct _node
After writing the code below: #include <iostream> using namespace std; typedef struct Node {

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.