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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:17:44+00:00 2026-05-31T19:17:44+00:00

I have a Class, it will be implemented to be many instances. I want

  • 0

I have a Class, it will be implemented to be many instances. I want to keep connections between some of the instances, and pass messages among them. In C++, I can do this like:

class A
{
   A (*connections)[];
   int sum;

public:
   void pass(int index)
   {
       connections[index] -> receive(sum);
   }
   void receive(int input)
   {
       sum += input;
   }
}

Then I only need to add pointers of other instances to connections[], I can pass messages among them with each other.

Currently I have to use Python doing this, but Python doesn’t support pointers. I wonder what is the proper solution, or design pattern, to solve this problem?

Thank you in advance.

  • 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-31T19:17:45+00:00Added an answer on May 31, 2026 at 7:17 pm

    Python doesn’t need pointers in order to achieve this as every variable is a reference to an object. These references are slightly different from C++ references, in that they can be assigned to – much like pointers in C++.

    So to achieve what you’re looking for, you’d just need to do something like this:

    class A(object):
        def __init__( self, connections, sum ):
            self.connections = connections
            self.sum = sum
    
        def passToConnections( self, index ):
            self.connections[ index ].receive( self.sum )
    
        def receive( self, input ):
           self.sum += input
    

    And just to prove that this works as expected:

    >>> a1 = A( [], 0 )
    >>> a2 = A( [], 0 )
    >>> a3 = A( [ a1, a2 ], 10 )
    >>> a3.passToConnections( 0 )
    >>> a3.passToConnections( 1 )
    >>> a3.passToConnections( 1 )
    >>> print a1.sum
    10
    >>> print a2.sum
    20
    

    So as you can see we have altered the original objects a1 and a2 by calling through to them via the references in a3

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

Sidebar

Related Questions

I have a class TDevice. Some devices will have a cellular module. So I
I have been looking to implement a custom class of : IList<ArraySegment<byte>> this will
I have written a class that will handle internal logging in my application. Now
I'm currently working on an oophp application. I have a site class which will
I have written an apex class that will create a PDF quote and attach
I have a static timer class which will be called by ANY webpage to
We have a static method in a utility class that will download a file
If you have data for a class that will be modified and needs to
So let's assume I have a class named ABC that will have a list
I have a buffer in class 'bufferClass' that will generate a signal to tell

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.