lbduballstrs
Baseband Member
- Messages
- 87
I'm writting this program for class and I can't get rid of these errors:
C:\Program Files\Microsoft Visual Studio\MyProjects\SparseMatrix\SparseSource.cpp(26) : error C2352: 'Matrix::getmatrix' : illegal call of non-static member function
b:\sparseheader.h(18) : see declaration of 'getmatrix'
C:\Program Files\Microsoft Visual Studio\MyProjects\SparseMatrix\SparseSource.cpp(27) : error C2352: 'Matrix:utmatrix' : illegal call of non-static member function
b:\sparseheader.h(19) : see declaration of 'putmatrix'
here is my code:
SparseHeade.h
#include<iostream>
using namespace std;
struct oneitem
{
int row, col;
float value;
};
oneitem sVariable;
const int MAXSIZE=225;
class Matrix
{
public:
void getmatrix (ifstream &);//reads the matrix from a file
void putmatrix (ofstream &);//write the matrix to a file
private:
oneitem data[MAXSIZE];
int rows,columns;//significant rows and columns
};
SparseSource.cpp
#include "b:\SparseHeader.h"//contains struct and class data
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream indata;
ofstream outdata;
indata.open("b:\\indata.txt");//disk file for input
if(!indata)
{
cout<<"Failed to open file indata.txt."<<endl;
return 1;
}//test fo opening indata.txt
outdata.open("b:\\outdata.txt");
if(!outdata)
{
cout<<"Failed to open file outdata.txt."<<endl;
return 1;
}//test for opening outdata.txt
Matrix::getmatrix(indata);
Matrix:utmatrix(outdata);
return 0;
}
void Matrix::getmatrix(ifstream & filedata)
{
filedata>>sVariable.row;
filedata>>sVariable.col;
while(filedata)
{
for( rows=0; rows<sVariable.row; rows++)
for(columns=0; columns<sVariable.col; columns++)
{
filedata>>sVariable.value;
data[rows+columns].value=sVariable.value;
}
}//end of while loop
}
void Matrix:utmatrix(ofstream & outfdata)
{
outfdata<<sVariable.row;
outfdata<<sVariable.col;
for(rows=0; rows<sVariable.row; rows++)
for(columns=0; columns<sVariable.col; columns++)
outfdata<<data[rows+columns].value;
}
If anyone knows the source of the errors I would greatly appreciate it.
Thanks
C:\Program Files\Microsoft Visual Studio\MyProjects\SparseMatrix\SparseSource.cpp(26) : error C2352: 'Matrix::getmatrix' : illegal call of non-static member function
b:\sparseheader.h(18) : see declaration of 'getmatrix'
C:\Program Files\Microsoft Visual Studio\MyProjects\SparseMatrix\SparseSource.cpp(27) : error C2352: 'Matrix:utmatrix' : illegal call of non-static member function
b:\sparseheader.h(19) : see declaration of 'putmatrix'
here is my code:
SparseHeade.h
#include<iostream>
using namespace std;
struct oneitem
{
int row, col;
float value;
};
oneitem sVariable;
const int MAXSIZE=225;
class Matrix
{
public:
void getmatrix (ifstream &);//reads the matrix from a file
void putmatrix (ofstream &);//write the matrix to a file
private:
oneitem data[MAXSIZE];
int rows,columns;//significant rows and columns
};
SparseSource.cpp
#include "b:\SparseHeader.h"//contains struct and class data
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream indata;
ofstream outdata;
indata.open("b:\\indata.txt");//disk file for input
if(!indata)
{
cout<<"Failed to open file indata.txt."<<endl;
return 1;
}//test fo opening indata.txt
outdata.open("b:\\outdata.txt");
if(!outdata)
{
cout<<"Failed to open file outdata.txt."<<endl;
return 1;
}//test for opening outdata.txt
Matrix::getmatrix(indata);
Matrix:utmatrix(outdata);
return 0;
}
void Matrix::getmatrix(ifstream & filedata)
{
filedata>>sVariable.row;
filedata>>sVariable.col;
while(filedata)
{
for( rows=0; rows<sVariable.row; rows++)
for(columns=0; columns<sVariable.col; columns++)
{
filedata>>sVariable.value;
data[rows+columns].value=sVariable.value;
}
}//end of while loop
}
void Matrix:utmatrix(ofstream & outfdata)
{
outfdata<<sVariable.row;
outfdata<<sVariable.col;
for(rows=0; rows<sVariable.row; rows++)
for(columns=0; columns<sVariable.col; columns++)
outfdata<<data[rows+columns].value;
}
If anyone knows the source of the errors I would greatly appreciate it.
Thanks