Hey,
I've been running into problems with this class I'm writing for file I/O. As I understand it, a stream is just a class - so I can do pointers with it like below, right? But it's giving me problems. Here are the relevant bits of code:
(File.h)
CODE
#ifndef FILE_H_
#define FILE_H_
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <GameState.h>
using namespace std;
/**
* This static class does all the file handling, including any necessary parsing of data.
* The two things files are used for are logging of statistics and storage of learned
* data for the learning AI.
*/
class File
{
public:
// Log file stuff. We only handle the one log file, specified in the Settings class.
static void OpenLogFile();
static void WriteLogLine(string strLine);
static void CloseLogFile();
// Learning file stuff (chooses file based on player name). Only one open at a time.
static void OpenPlayerFile(string strName);
// Get stored Value for a state-action pair.
static int GetValue(GameState *oState, int iUnit);
// Change the stored Value for a state-action pair
static int WriteValue(GameState *oState, int iUnit, int iNewVal);
static void ClosePlayerFile();
private:
static fstream *fsPlayerFile;
static ofstream *fsLogFile;
};
#endif /*FILE_H_*/
(File.cpp)
CODE
#import <File.h>
void File::OpenLogFile()
{
fsLogFile = new ofstream("fe");
}
The error it gives me is "undefined reference to `File::fsLogFile'" at the line where I try to initialise the log file stream. Am I missing something really obvious here?