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

  • Home
  • SEARCH
  • 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 3840828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:34:29+00:00 2026-05-19T15:34:29+00:00

My question is how to access and modify a 2D array defined in one

  • 0

My question is how to access and modify a 2D array defined in one class that is friends with another class. Below are some details on my question:

In class A I declare and allocate the appropriate space for my 2D array (pointer-to-pointer) u.

Class A
{
   public:
   friend class B;
   long double **u; 
   int fun;
   void make(); 
};
void A::make()
{
  long double **u = new long double *[nx];
  for (int i=0;i<nx;i++)
  u[i] = new long double [ny];
  int fun = 9;
}

Class A is friends with Class B; I need to use the array I declared in Class A in a function defined in class B. Below is my Class B:

class B
{
   public:
   void get(A*);
};

void B::get(A *pt)
{
   using namespace std;
   cout << pt->fun;
   cout << pt->u[0][0];
}

I get a Bus error on my second cout pt->u[0][0]. Is there a simple way to use this setup I have to access my u[][] array? I think that I get the error because the pointer points to the 1st entry of my array, thus my whole 2D array is saved in memory as a single row (thinking aloud here). I’m a Fortran guy so this stuff is a little new to me.

Any help or “pointers” to other helpful threads would be appreciated.

Thank you !

Alberto

  • 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-19T15:34:30+00:00Added an answer on May 19, 2026 at 3:34 pm

    I think you get error because A::u is not initialized ( in method A::make you initialize a local variable u, not member. You need to change

    void A::make()
    {
      long double **u = new long double *[nx]; // should be just u, or this->u.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is similar to this one: Restrict method access to a specific class
Question summary: How do I modify the code below so that untrusted, dynamically-loaded code
I have a smple Question: How can I access to a class and its
Friends, This Ask Tom thread which I found via another SO question, mentions Table
I'm trying to access and modify the private data member of a class by
I have a question about Access.If for example I have a table with the
I have a short access/mySQL question. I have a mapping table on the format
Basically this is a question how to access local scope handler. I trying to
my question is about two possible ways to access data: (My question is about
Basic question - is it possible to access the current Page from a static

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.