0

I want to be able to use private variables from one class in another class fx with regards to A_class I want to be able to use the values of the int n,m and the arrays A and b. With regards to a and m I tried setting them equal to public variables, but that didn't work

class A_class{
public:

void Indlaes();

private:
double A[Nmax][Nmax],b[Nmax];
int n,m;
};

class B{
public:
void Indtast_b();
void Overfoer_b();

private:
double A[Nmax][Nmax],b[Nmax];
int n,m;
};

class C{
public:
void Indlaes_C();
void Indtast_C1();
void Indtast_C2();
void Overfoer_C();
void Projektion_b();

private:
double A84[Nmax][Nmax],Q[Nmax][Nmax],R[Nmax][Nmax],A[Nmax][Nmax],b[Nmax];
int n,m;
};

class Metode1{
public:

void brug2(double A1[Nmax][Nmax],double b1[Nmax]){

        for(int i=0;i<n;++i){
            for(int j=0;j<m;++j){
                A[i][j]=A1[i][j];
            }
        }
        for(int i=0;i<n;++i)b[i]=b1[i];

}

void Metode1_MatrixProd();
void Metode1_MatrixVekProd();
void Metode1_DanTotalMatrix();
void Metode1_Gauss();
void Metode1_Backwardsubstitution();
void Metode1_UdskrivVektor();
void Kontrol_Metode1();
private:
double A[Nmax][Nmax],M[Nmax][Nmax],AT[Nmax][Nmax],b[Nmax],W[Nmax],TM[Nmax][Nmax],FM[Nmax][Nmax],sum,x[Nmax],bpNy[Nmax];
int n,m;
};
19181918
  • 37
  • 1
  • 7
  • Please read about the [`friend` keyword](https://stackoverflow.com/questions/17434/when-should-you-use-friend-in-c), which does what you want to do. – Ken Y-N May 29 '16 at 23:51
  • http://stackoverflow.com/questions/1568091/why-use-getters-and-setters –  May 30 '16 at 02:09

1 Answers1

0

If you want other classes to have access to certain variables, you should use public and inheritance.

 class A_class
 {
 public:
 int whatever;
 };

 #include "A_class"
 class B : public A_class
 {
 public:
 // stuff
 };
sntnmjones
  • 15
  • 9