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

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

The Archive Base Latest Questions

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

I have a class class Node { public: int value; Node * next; Node();

  • 0

I have a class

class Node {

  public:
    int value;
    Node * next;

    Node();
    Node(const Node& other);
    Node& operator= (const Node& other);
};

It’s not very useful, but it has an overridden assignment operator. Everything in there is public because I am such an open and cooperative guy.

Now elsewhere I have an array of these nodes:

Node * nodes = new Node[15];

When I try to assign a node to my array of nodes:

nodes[0] = Node();

I get a huge ugly crash.

My assignment operator looks like this:

Node& Node::operator= (const Node& other) {

  // watch out for self assignment
  if (this == &other) return *this;

  delete this->next;
  this->next = new Node(*(other.next)); // call the copy constructor
  this->value = other.value;

  return *this;
}

I get the feeling that I should be checking for whether or not this is NULL before I go about trying to dereference its members. Any thoughts on what might be 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-26T03:36:11+00:00Added an answer on May 26, 2026 at 3:36 am

    The problem is that you’re dereferencing other.next, which might be NULL. So you should check if other.next is null before dereferencing it:

    this->next = other.next ? new Node(*other.next) : 0;
    

    Dereferencing a NULL pointer is undefined, so if you do it, anything might happen — it might NOT crash immediately and instead wander off into unexpected places, confusing both you and the debugger.

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

Sidebar

Related Questions

I have a class named Node as follow Public class T{ int value; public
I have this very simple C++ class: class Tree { public: Node *head; };
I have a class Node: class Node { public: int item; Node * nextLink;
I have the following class class Node { int key; Node**Nptr; public: Node(int maxsize,int
I have this class: public class Source extends Node { protected DistributionSampler delay ;
I have an node object which specifies the node level public class Node {
I have a base class Node which contains a list of child nodes. Node
Im having a problem with python.. I have a binary tree node type: class
I have a binary tree class that is created with a root node and
I have class A: public class ClassA<T> Class B derives from A: public class

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.