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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:07:00+00:00 2026-06-10T13:07:00+00:00

Part of the task I have is to create a class, which contains two

  • 0

Part of the task I have is to create a class, which contains two lists of two other classes and create “The big 4″(constructor, copy constructor, operator=, destructor)

Here’s what I did:

using namespace std;

class A{...};
class B{...};

class C{
  list<A> a;
  list<B> b;
  public:
    C();
    ~C();
    C(const C& c);
    void operator=(const C& c);
};

C::C(){
  //How to allocate memory for a and b?
}

C::~C(){
  //How to free the memory?
}

C::C(const C& c){
  a=c.a;
  b=c.b;
}

void operator=(const C& c){
  if(&c==this) return;
  // how do I delete a and b?
  a=c.a;
  b=c.b;
}

Could you clear out the things that I don’t understand(as comments in the code). And also give advice if I haven’t done anything correctly?

  • 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-10T13:07:01+00:00Added an answer on June 10, 2026 at 1:07 pm

    Since you’re using values (std::list values), there is nothing to do. Your constructor will call the std::list constructors automatically, which allocate any resources needed. Your destructor will call the std::list destructor, which frees resources which it acquired.

    You would need some extra work if you either hold pointers to lists (i.e. std::list<A> *a;) or lists of pointers (std::list<A*> a;') – or both (std::list<A*> *a;).

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

Sidebar

Related Questions

My task consists of two parts. First I have to create globbal char array
I have a a service class which includes an Async task. In the doInBackground
In one app, I have a task to create files that will be used
I have the following issue whith this very simple task. I want to create
I have to complete this task: I'm given a xml file which is exported
I have NAnt script which as part of its project calls a batch file
I have only started learning Java. My task is to create a file server
As part of a larger task performed in R run under windows, I would
I've been given the task of re-engineering a really old VB3 application. As part
I am quite new to web development and have a task to develop a

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.