Dwa takie same błędy kompilacji
illegal reference to non-static member 'cFile::filesize'
w momencie kompilowania każdej z tych dwóch linijek:
Kod:
{ return cFile::filesize; }
oraz
Kod:
{ cFile::filesize = new_filesize; }
Zdaje mi się, że problem jest w tym, iż nie tworzę obiektu przy pomocy new. Nie wiem, jak sobie poradzić z tym błędem. Próbowałem przy pomocy this, ale coś mi to nie wychodzi.
Pozdrawiam!
cFile.h
Kod:
#ifndef CFILE_H
#define CFILE_H
#include <string>
class cFile
{
public:
cFile(std::string filename);
//accessor to filename
std::string show_filename();
long int show_filesize();
void changes_filesize(long int new_filesize);
private:
std::string filename;
long int filesize;
/*
cFile *current_file; //I need to know current file to use accessors
//I initialize its value in the destructor
*/
};
#endif
cFile.cpp
Kod:
#include "stdafx.h"
/*#include "cFile.h"
#include <string>*/
/**
* default constructor with use of initialization list
* creates new file of a given name
*/
cFile::cFile(std::string filename) : filename(filename)
{ //current_file = this;
}
std::string cFile::show_filename() {return filename;} //or cFile::filename (?)
long int show_filesize()
{ return cFile::filesize; }
void changes_filesize(long int new_filesize)
{ cFile::filesize = new_filesize; }