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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:54:13+00:00 2026-05-28T02:54:13+00:00

I have a relationship of composition between class A and B, class A {

  • 0

I have a relationship of composition between class A and B,

class A
{
    A(); //default constructor  //EDIT
    A(const A &mA); // copy constructor //EDIT
    virtual ~A();
};


class B
{
B(A *pA); //constructor
B(const B &mB) //copy constructor
virtual ~B(); //EDIT: destructor to eliminate mA and to build the composition
A* mA;
};

Could I write the copy constructor in this manner:

B(const B &mB, A *pA)

I need it to keep up the composition also between the copied objects.
Is it wrong? Does it exist a better solution?
Thank you

EDIT: I’ll try to explain me better. I want a copy of the object mB and the object mA. But if in the copy constructor I had writen mA =mB.mA I would copy the adress to the original object mA. So I think I need a deep copy not an swallow copy. My confusion arise because now, from the main, first I copy the object mA and then I copy mB. Doing that, I think I need to assign the copied object mA with an external function like

foo(A *pA)

Otherwise I could solve the problem if I could doing a deep copy of mB. Is this called a deep copy?

P.S.
A and B are abstract classes

  • 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-28T02:54:14+00:00Added an answer on May 28, 2026 at 2:54 am

    No. By definition, the copy constructor can not have a signature like the one you described. Here are some valid signatures for copy constructors:

    B(const B &);
    B(B &);   // Thanks Oli!
    

    Why do you need it? You can access the mA member inside the copy constructor by doing something like this (I might have made some syntax errors):

    B::B(const B & original)
    {
        mA = original.mA;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relationship between two base classes: public abstract class RecruiterBase<T> { //
I have a relationship between two tables, authors and styles. Every author is associated
Ok, I have a relationship between People, Users and Employees such that All Employees
i have relationship: // In A.java class @OneToMany(mappedBy=a, fetch=FetchType.LAZY) @Cascade(CascadeType.SAVE_UPDATE) private List<B> bList; //
I have a relationship like this: class E { string name hasMany = [me:ME]
I have this relationship in a Rails app class Folder has_many :elements end class
If I have a relationship between two tables (both tables have their own primary
When I design classes and have to choose between inheritance and composition, I usually
I have a one to many relationship between two tables. The many table contains
I have a class that have a relationship with itself: public class Person {

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.