1. ## Problem with .CPP program output HELP please!!!

I am a beginner in C++ .i wrote this code in which operator is overloaded on matrices.Go thru the program;
Code:
``` :
/*prog.cpp*/
#include<iostream.h>
#include<conio.h>
int k=1;
class matrix
{
private:
static int a[20][20];
int m,n;
public:
friend istream& operator>>(istream &cin,matrix&);
friend ostream& operator<<(ostream &cout,matrix);
friend matrix operator+(matrix,matrix);
friend matrix operator-(matrix,matrix);
friend matrix operator*(matrix,matrix);
friend matrix operator/(matrix,matrix);
};

istream& operator>>(istream &cin,matrix &a)
{
int i,j;
cout<<"Enter the size of the matrix m,n"<<endl;
cin>>a.m>>a.n;
cout<<"Enter the matrix"<<endl;
for(i=0;i<=a.m-1;i++)
for(j=0;j<=a.n-1;j++)
cin>>a.a[i][j];
return(cin);
}
ostream& operator<<(ostream &cout,matrix a)
{
int i,j;
cout<<"The matrix is as follows"<<endl;
for(i=0;i<=a.m-1;i++)
{
for(j=0;j<=a.n-1;j++)
cout<<a.a[i][j]<<"\t";
cout<<"\n";
}
return(cout);
}
matrix operator+(matrix a,matrix b)
{
matrix c;
int i,j;
c.m=a.m;
c.n=a.n;
for(i=0;i<=a.m-1;i++)
for(j=0;j<=a.n-1;j++)
c.a[i][j]=a.a[i][j]+b.a[i][j];
return(c);
}

matrix operator-(matrix a,matrix b)
{
matrix c;
int i,j;
c.m=a.m;
c.n=a.n;
for(i=0;i<=a.m-1;i++)
for(j=0;j<=a.n-1;j++)
c.a[i][j]=a.a[i][j]-b.a[i][j];
return(c);
}
matrix operator*(matrix a,matrix b)
{
matrix c;
int i,j;
c.m=a.m;
c.n=b.n;
if(a.n==b.m)
{
for(i=0;i<=a.m-1;i++)
for(j=0;j<=b.n-1;j++)
for(k=0;k<=a.n-1;k++)
c.a[i][j]+=a.a[i][k]+b.a[k][j];
}
else
k=0;
return(c);
}
matrix operator/(matrix a,matrix b)
{
matrix c;
int i,j;
c.m=a.m;
c.n=a.n;
for(i=0;i<=a.m-1;i++)
for(j=0;j<=a.n-1;j++)
c.a[i][j]=(float)a.a[i][j]/float(b.a[i][j]);
return(c);
}
main()
{
matrix a,b,c,d,e,f;
cin>>a>>b;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
cout<<"The subtraction of matrices is:"<<"\n"<<d;
if(k==1)
cout<<"The multiplication of matrices is:"<<"\n"<<e;
else
cout<<"The multiplication of matrices is not possible"<<endl;
cout<<"The division of matrices is:"<<"\n"<<f;
getch();
return(0);
}```
When i compile the above prog i get an error :
"Linker error:undefined symbol matrix::a in module prog.cpp"

2. Why is the member array a static?

3. Code:
```class matrix
{
private:
static int a[20][20];```

u need to declare static int a[20][20] outside the class and use it directly.

4. thanks 4 helping me out.The main problem was that a clas cannot have a static member.
thx

5. A class can have a static member, you just didn't implement it completely. In this case, though, the array shouldn't have been static anyway since each matrix instance should have its own data.