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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:00:51+00:00 2026-06-18T12:00:51+00:00

Copy Constructor: // Copy constructor. Copies another list. CRevList(const CRevList &b) { cout <<

  • 0

Copy Constructor:

 // Copy constructor.  Copies another list.

CRevList(const CRevList &b)
 {
    cout << "Copy" << endl;

    const Node *Start = b.Begin();

    const Node *End = b.End();

    cout << "Start; " << Start << endl;

    cout << "End; " << End << endl;

    cout << "b.Begin() : " << b.Begin() << endl;
    cout << "b.End()   : " << b.End() << endl;
    T temp_data;

    for(;;){
            cout << "Start->data() loop: " << Start->Data() << endl;

            temp_data = Start->Data();

            PushBack(temp_data);


            if(Start == End)
                    break;

            Start = Start->m_next;


    }

}

Call to End to get pointer to tail node (Begin() is the same):

const Node *End() const {}

   Node *End() {
      cout << "m_tail " << m_tail << endl;
      return m_tail;
   }

Sorry for the amount of code. I just can’t figure out where I’m going wrong

Edit: okay here’s a minimal complete example

Driver

using namespace std;

#include <iostream>
#include "RevList.h"

int main(){

    CRevList<int> List;
    List.PushBack(7);
    List.PushBack(300);
    cout << "End Ref: " << List.End() << endl;
    cout << "begin ref: " << List.Begin() << endl;
    cout << List.End() << endl;

    CRevList<int> New_list(List);

    cout << "End Ref: " << New_list.End() << endl;
    cout << "begin ref: " << New_list.Begin() << endl;



}

Implementation of doubly linked list:

template<class T> class CRevList
{

public:
//constructor stuff doesn't matter... ;

class Node
{
public:
 friend class CRevList;

 Node() {m_next = 0;  m_prev = 0;}
 Node(const T &t) {m_payload = t;  m_next = 0;  m_prev = 0;}

 T Data() {return m_payload;}
 const T Data() const {return m_payload;}

private:
 Node    *m_next;
 Node    *m_prev;
 T       m_payload;
};

  //Push Back ////////////////////////////////////////////////
  void PushBack(const T &t) {
      Node * Temp = new Node(t);


      if(IsEmpty()){
            cout << "is Empty" << endl;
              m_head = Temp;

              m_tail = Temp;

      }
      else{
            Node * Curr = m_tail;

            Curr->m_next = Temp;

            Temp->m_prev = Curr;

            m_tail = Temp;


      }

      size += 1;

 }


//Get a pointer to the first node in the list
const Node *Begin() const {}
Node *Begin() {
       cout << "m_head " << m_head << endl;
       return m_head;
} 


//get a pointer to the last node in the list
const Node *End() const {}

Node *End() {
       cout << "m_tail " << m_tail << endl;
 return m_tail;
}

private:


Node    *m_head, *m_tail;             // Head node
unsigned size;



};

};

AND finally output from driver

m_tail 0x2068030
End Ref: 0x2068030
m_head 0x2068010
begin ref: 0x2068010
m_tail 0x2068030
0x2068030
Copy
Start; 0x7fff7745d240
End; 0x7fff7745d240
b.Begin() : 0x7fff7745d240
b.End()   : 0x7fff7745d240
Start->data() loop: 2
Segmentation fault  //don't care about this right now
  • 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-18T12:00:53+00:00Added an answer on June 18, 2026 at 12:00 pm

    You forgot to initialize size.

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

Sidebar

Related Questions

Right now I'm working with a copy constructor for taking a list called val
I need to write a copy constructor that deep copies the contents of a
What does this statement mean? A default copy constructor or default copy assignment copies
I'm using a copy constructor to take a MapObject and copy it and it's
I recently revisited the copy constructor, assignment operator, copy swap idom seen here: What
clone method vs copy constructor in java. which one is correct solution. where to
Why must a copy constructor's parameter be passed by reference?
I have never written copy constructor, so in order to avoid pain i wanted
when this copy constructor is called in my application, this copy constructor goes into
Possible Duplicate: Copy Constructor is not invoked # include <iostream> using namespace std; 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.