Im trying to create a log class which all my projects classes is going to write to. It looks like this:
#ifndef _LOG
#define _LOG
#include <fstream>
class Log {
private:
std::ofstream log; // the log file
public:
Log() {
log.open("Log.txt"); //Automatically deletes any existing file, you have to tell it to append for it not to.
std::clog.rdbuf(log.rdbuf()); //Redirect clog to output to file.
}
~Log() {log.close();};
// log file function
void Write(std::string message) {std::clog << message << std::endl;}
};
#endif
The "Game" class has an instance of the "AsciiMap" class. The AsciiMap wants an adress to a log class so it knows where to send the log strings.
AsciiMap.h
#include "Log.h"
class AsciiMap {
private:
Log* Log; // pointer to the log class
public:
AsciiMap(int x, int y, Log* LogFile); // sizes the ascii map to the size specified
The part in AsciiMap's constructor where I store the Log adress looks like this:
Log = LogFile; // store the adress to the logfile, if NULL is sent, no logs will be written
Game has an instance of Log as well and when Game is created, it send the adress of Log to the AsciiMap class:
Game::Game() : AsciiMap( RESX / GRIDSIZE, RESY / GRIDSIZE, &Log)
But it wont work and the compiler just spits errors at me. This is the first time Im using pointers for real and in the tutorials I only used them on a couple of int's and in small arrays. I think Ive missunderstood some key element here.
Heres the errors I get:
AsciiMap.cpp
d:\Documents\CPP\Visual Studio Projects\SDL\AsciiMap.cpp(3) : error C2061: syntax error : identifier 'Log'
d:\Documents\CPP\Visual Studio Projects\SDL\AsciiMap.cpp(3) : error C2511: 'AsciiMap::AsciiMap(int,int)' : overloaded member function not found in 'AsciiMap'
d:\Documents\CPP\Visual Studio Projects\SDL\AsciiMap.h(17) : see declaration of 'AsciiMap'