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

The Archive Base Latest Questions

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

I have a class A consisting of a bunch of internal data structures (e.g.

  • 0

I have a class A consisting of a bunch of internal data structures (e.g. m_data) and a few objects (e.g. ClassB):

class A
{
public:
      ...
private:
      int m_data[255];
      ClassB B[5];
}

What’s the best way for B to access m_data? I don’t want to pass m_data into B’s function..

// updated:
Many thanks for the responses. Let me provide more contextual info.
I am working on an AI project, where I got some data (e.g. m_data[i]) at each time step. The class A needs to buffer these information (m_data) and uses a list of B’s (example updated) to make inference. Class B itself is actually a base class, where different children derive from it for different purpose so I guess in this context, making B a subclass of A might not be clean (?)..

  • 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-26T04:22:10+00:00Added an answer on May 26, 2026 at 4:22 am

    Ideally, you don’t allow external access the data structure at all. You should rethink your approach, considering more the question “What are the functional requirements / use cases needed for ClassB to access instances of A” rather than offloading the management of the internal members to methods not managed within class A. You will find that restricting management of internal members to the class owning those members will yield cleaner code which is more easily debugged.

    However, if for some reason this is not practical for your situation there are a couple possibilities that come to mind:

    • You can provide simple get/set accessor methods which, depending upon
      your requirements, can be used to access either a copy of or a
      reference to m_data. This has the disadvantage of allowing everybody
      access, but does so only through well defined interfaces (which can
      be monitored as needed).
    • ggPeti mentions use of friend, which may work for you, but it gives ClassB access to all of the internals of A.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class library containing several structures each consisting of several value and
I have a simple class as defined below: public class Person { int _id;
I have a following class public class People { public int id; public string
I have class A: public class ClassA<T> Class B derives from A: public class
I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter
I have class A: public B { ...} vector<A*> v; I want to do
I have a small Python program consisting of very few modules (about 4 or
Let's Say I Have This Class: package{ import flash.display.Sprite; public class Main extends Sprite{
I have a bare bones ORM implementation, consisting of data mappers which load and
I'm writing a program consisting of dynamically created panels that each have a few

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.