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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:58:52+00:00 2026-06-02T22:58:52+00:00

I’ve got the following classes: class A { // Whatever }; class B {

  • 0

I’ve got the following classes:

class A {
    // Whatever
};

class B {
    T attribute;
    A a;
};

Now suppose i have the following scenario:

A aX, aY;  
B bX, bY;  

Now i can sort of “insert” aX or aY into bX or bY.

I would like for the objects of type A to know, what B they are in, or in other words, what is the “attribute” of their “superclass” B.

Question:

I would like to be able to move the objects of type A freely between their “superclasses” B and i need a way to leak the attribute of B to them dynamically at runtime, so the objects of type A always know, what B they belong to (or what is the attribute of B they are currently in).

What is the best way to do it ?

  • 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-02T22:58:54+00:00Added an answer on June 2, 2026 at 10:58 pm

    Perhaps this is useful (pointer from the owner to the attribute, and the reverse):

    class A;
    
    class B {
        T attribute;
        A* a;
    public:
       void setA(A* newA);
       T getAttribute() {return attribute;}
       void setAttribute() {/*some code*/}
    };
    
    class A {
       B* Owner;
       friend void B::setA(A* newA);
    public:
        void setOwner(B* newOwner) {
            newOwner->setA(this);
        }
    };
    
    void B::setA(A* newA)
    {
        A* tempA = this->a;
        B* tempB = newA->Owner;
    
        tempA->Owner = NULL;
        tempB->a = NULL;
    
        this->a = newA;
        newA->Owner = this;
    }
    

    UPDATED: Fixed a bug in cycle-pointing and cycle-calling, it could be solved only with a friend function.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.