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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:16:26+00:00 2026-05-24T04:16:26+00:00

I have 4 classes: A, B, C and D. A is really a main

  • 0

I have 4 classes: A, B, C and D.

A is really a main class, and has instances of B, C and D:

class A() {

  var B_class : B = new B()
  var C_class : C = new C()
  var D_class : D = new D()

}

The D class has methods that use methods from C class. But these methods need to know the state of C class.

So my understanding is I would need to pass C class in as a parameter when constructing D class like so:

class A() {

  var B_class : B = new B()
  var C_class : C = new C()
  var D_class : D = new D(C_class)

}

But the other issue is the fact that C_class also needs to use methods from D_class that change the state of D_class. If everything was in one class it’d be easy.

Sure, I could just have methods that take specific classes, but there must be a better way. I’m confident I’ve overlooked something basic in my design.

  • 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-24T04:16:27+00:00Added an answer on May 24, 2026 at 4:16 am

    I’m not sure if this applies to your OO language, but in you can easily have C_class contain a reference to D and D_class a reference to C:

    class C;
    class D;
    
    class C
    {
      D & otherD;
    
    public:
      C(D & d) : otherD(d) { }
    };
    
    class D
    {
      C & otherC;
    
    public:
      D(C & c) : otherC(c) { }
    };
    
    class A
    {
      C myC;
      D myD;
    
    public:
      A() : myC(myD), myD(myC) { }
    };
    

    The key is that it’s possible to have pointers and references to incomplete types. Since you don’t need actual mutually nested members (which wouldn’t make sense anyway), but only references, you can easily have circular references like this.

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

Sidebar

Related Questions

I have a class that only really ever needed by classes in a certain
I have a few classes in a project that I inherited that are really
I have classes that store data, and methods to go get data for individual
I have a main class that configures and fires up Jetty. (That's standard practice
I've got a program where a lot of classes have really complicated configuration requirements.
I am really confused about object relationships! I have two classes Person and Address.
I have classes that are named exactly the same across different plug-ins that I
I have classes that are needed in both my web service and my server.
If I have classes of Type A and B: public class A { public
If you have a namespace that contains a property in ClassA and a 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.