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;
};
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
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.