I started to work with SDL and decided to write my own class for working with it, for showing errors, loading images, etc.
I made a class called MySDL containing sub-classes like the class Errors that should write errors into a file that I can set. I want this class to be static, to use it without creating any object out of it so I declared every member of the class static and set the destructor to zero so that I can't make an object out of it. The problem is when I use the string that holds the name of the file (error_log.txt for example) in an ofstream object to create the file and write into it, it gives the error of "Unresolved Externals" and this warning
Warning 1 warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library C:\Users\Marek\Desktop\C++\MSVC\SDL_Project 0\SDL_Project 0\MSVCRTD.lib(cinitexe.obj)
Here is the *.h file of the class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#ifndef _FUNC_H_
#define _FUNC_H_
class MySDL
{
public:
class Errors
{
public:
Errors() { ShowDate = true; FileName = "error_log.txt"; }
virtual ~Errors() = 0;
static void setWriteFile(std::string Filename) { FileName = Filename; }
static std::string getWriteFile() { return FileName; }
static void WriteToFile(std::string Message);
static void isShowDate(bool val) { ShowDate = val; }
private:
static bool ShowDate;
static std::string FileName;
};
private:
};
#endif
|
and here is the *.cpp file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL_mixer.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <string>
#include <sstream>
#include <fstream>
#include "func.h"
//Errors Class
MySDL::Errors::~Errors() { }
void MySDL::Errors::WriteToFile(std::string Message)
{
std::ofstream file;
std::string filename_copy = Errors::FileName;
file.open(filename_copy,std::ios::app);
file << Message << " ";
file << '\n';
file.close();
}
|
I always try to figure a problem by myself before asking, but this took me a lot of time and I didn't find the error... I tried renaming the string FileName to different names... I gave to the .open() instead of the string FileName another string, worked fine... I even made a char for the string to copy into but as I used the string ... "Unresolved externals".
It's is truly an EPIC FAIL that my error showing class has errors in itself...