Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » eillegal call of non-static member function error
Closed Thread
Old 11-14-2005, 03:42 PM   #1 (permalink)
 
Junior Techie

Join Date: Nov 2005

Posts: 87

lbduballstrs

Default eillegal call of non-static member function error

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
lbduballstrs is offline  
Old 11-14-2005, 05:04 PM   #2 (permalink)
 
Ultra Techie

Join Date: Jul 2005

Posts: 530

TheHeadFL

Send a message via AIM to TheHeadFL
Default

You need to create an instance of Matrix class and call with:

instance.getmatrix()

:: is the "Scope Resolution Operator" and is used only with static member functions or constants, and should not be used in this application. That is unless you intend to make those functions statics.
__________________
Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache)
TheHeadFL is offline  
Old 11-14-2005, 05:41 PM   #3 (permalink)
 
Super Techie

Join Date: Jan 2005

Posts: 295

gab00n

Default

Also you should always create your own class constructors and destructors, you can never rely on what the compiler gives you. Even if they don't do anything just have them in there.

You should also put the class member functions definitions in their own implementation file .cpp or implement them right inside the class.
__________________
\"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla
gab00n is offline  
Old 11-15-2005, 12:14 PM   #4 (permalink)
 
Junior Techie

Join Date: Nov 2005

Posts: 87

lbduballstrs

Default

Got it.Thanks for the help.
lbduballstrs is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On