Hallo Zusammen,
ich wollte mir mal das Programmieren ein bisschen anschauen und habe mich deshalb in das Buch "C++ für Spieleprogrammierer
vertieft. Bis jetzt haben alle Beispielquelltexte bei mir einwandfrei funktioniert, doch das Logfile scheint einen Fehler zu enthalten,
denn selbst die Version von der CD-ROM funktioniert bei mir nicht.
Vielleicht weiß ja jemand von euch vorans es liegen könnte,
vielen Dank schonmal im Voraus!
Singleton.hpp:
|
C-/C++-Quelltext
|
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
31
32
33
34
35
36
37
38
|
#ifndef TSINGLETON
#define TSINGLETON
template <class T>
class TSingleton
{
protected:
static T *m_pSingleton;
public:
virtual ~TSingleton()
{
}
inline static T* Get()
{
if (!m_pSingleton)
m_pSingleton = new T;
return (m_pSingleton);
}
static void Del()
{
if (m_pSingleton)
{
delete (m_pSingleton);
m_pSingleton = NULL;
}
}
};
template <class T>
T* TSingleton<T>::m_pSingleton = 0;
#endif
|
Logfile.hpp:
|
C-/C++-Quelltext
|
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#ifndef __CLOGFILE
#define __CLOGFILE
#include <windows.h>
#include <stdio.h>
#include "Singleton.hpp"
#define MAX_BUFFER 1024
#define L_FAIL false
#define L_OK true
#define g_pLogfile CLogfile::Get()
enum FONTCOLORS
{
BLACK,
RED,
GREEN,
BLUE,
PURPLE
};
class CLogfile : public TSingleton<CLogfile>
{
public:
CLogfile();
~CLogfile ();
void CreateLogfile (const char *LogName);
void WriteTopic (const char *Topic, int Size);
void Textout (const char *Text);
void Textout (int Color, const char *Text);
void Textout (int Color, bool List, const char *Text);
void fTextout (const char *Text, ...);
void fTextout (int Color, const char *Text, ...);
void fTextout (int Color, bool List, const char *Text, ...);
void FunctionResult (const char *Name, bool Result);
private:
FILE *m_Logfile;
};
#endif
|
Logfile1.cpp:
|
C-/C++-Quelltext
|
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#include "Logfile.hpp"
CLogfile::CLogfile()
{
}
CLogfile::~CLogfile()
{
Textout ("<br><br>End of logfile</font></body></html>");
fclose (m_Logfile);
}
void CLogfile::CreateLogfile (const char *LogName)
{
m_Logfile = fopen (LogName, "w");
Textout ("<html><head><title>Logfile</title></head>");
Textout ("<body><font face='courier new'>");
WriteTopic ("Logfile", 3);
#ifdef _DEBUG
Textout ("BUILD: DEBUG<br>");
#else
Textout ("BUILD: RELEASE<br>");
#endif
Textout ("<a href='mailto:support@meineURL.de?subject=Logfile'>");
Textout ("Send E-Mail to me</a><br><br>");
fclose (m_Logfile);
m_Logfile = fopen (LogName, "a");
}
void CLogfile::WriteTopic (const char *Topic, int Size)
{
Textout ("<table cellspacing='0' cellpadding='0' width='100%%' ");
Textout ("bgclolor='#DFDFE5'>\n<tr>\n<td>\n<font face='arial' ");
fTextout("size='+%i'>\n", Size);
Textout (Topic);
Textout ("</font>\n</td>\n</tr>\n</table>\n<br>");
fflush (m_Logfile);
}
void CLogfile::Textout(const char *Text)
{
fprintf (m_Logfile, Text);
fflush (m_Logfile);
}
void CLogfile::Textout(int Color, const char *Text)
{
Textout (Color, false, Text);
}
void CLogfile::Textout(int Color, bool List, const char *Text)
{
if(List==true)
Textout ("<li>");
switch(Color)
{
case BLACK:
Textout ("<font color=black>"); break;
case RED:
Textout ("<font color=red>"); break;
case GREEN:
Textout ("<font color=green>"); break;
case BLUE:
Textout ("<font color=blue>"); break;
case PURPLE:
Textout ("<font color=purple>"); break;
};
Textout (Text);
Textout ("</font>");
if (List==false)
Textout ("<br>");
else
Textout ("</li>");
}
void CLogfile::fTextout(const char *Text, ...)
{
TCHAR buffer[MAX_BUFFER];
va_list pArgList;
va_start (pArgList, Text);
vsprintf (buffer, Text, pArgList);
va_end (pArgList);
Textout(buffer);
}
void CLogfile::fTextout(int Color, const char *Text, ...)
{
TCHAR buffer[MAX_BUFFER];
va_list pArgList;
va_start (pArgList, Text);
vsprintf (buffer, Text, pArgList);
va_end (pArgList);
Textout(Color, buffer);
}
void CLogfile::fTextout(int Color, bool List, const char *Text, ...)
{
TCHAR buffer[MAX_BUFFER];
va_list pArgList;
va_start (pArgList, Text);
vsprintf (buffer, Text, pArgList);
va_end (pArgList);
Textout(Color, List, buffer);
}
void CLogfile::FunctionResult(const char *Name, bool Result)
{
if (L_OK == Result)
{
Textout("<table width='100%%' cellSpacing='1' cellPadding='5'");
Textout(" border='0' bgcolor='#C0C0C0'><tr><td bgcolor='");
fTextout("'#FFFFFF' width='35%%'>%s</TD>", Name);
Textout("<td bgcolor='#FFFFFF' width='30%%'><font color =");
Textout("'green'>OK</FONT></TD><td bgcolor='#FFFFFF' ");
Textout("width='35%%'>-/-</TD></tr></table>");
}
else
{
Textout("<table width='100%%' cellSpacing='1' cellPadding='5'");
Textout(" border='0' bgcolor='#C0C0C0'><tr><td bgcolor=");
fTextout("'#FFFFFF' width='35%%'>%s</TD>", Name);
Textout("<td bgcolor='#FFFFFF' width='30%%'><font color=");
Textout("'red'>ERROR</FONT></TD><td bgcolor='#FFFFFF' ");
Textout("width='35%%'>-/-</TD></tr></table>");
}
}
|
Listing_8.15:
|
C-/C++-Quelltext
|
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
31
32
33
34
35
36
37
38
39
|
/*
C++ für Spieleprogrammierer
Listing 8.15
Anwendung der Logfile-Klasse
*/
#include <iostream>
#include "Logfile.hpp
using namespace std;
int main()
{
float Kontrolle = 123.456f;
g_pLogfile->CreateLogfile("Logfile.html");
g_pLogfile->WriteTopic("Unformatierter Text", 2);
g_pLogfile->Textout("Normaler, schwarzer Text<br>");
g_pLogfile->Textout(RED, "Farbiger Text in Liste (1)");
g_pLogfile->Textout(BLUE, "Farbiger Text in Liste (2)");
g_pLogfile->Textout(BLUE, "Farbiger Text in Liste (3)");
g_pLogfile->WriteTopic("Formatierter Text", 2);
g_pLogfile->fTextout("Kontrollvariable: %f<br>", Kontrolle);
g_pLogfile->fTextout(RED, "Kontrollvariable: %f<br>", Kontrolle);
g_pLogfile->fTextout(GREEN, true, "Liste Kontrolle: %f", Kontrolle);
g_pLogfile->fTextout(GREEN, true, "Liste Kontrolle: %f", Kontrolle*2.0f);
g_pLogfile->fTextout(GREEN, true, "Liste Kontrolle: %f", Kontrolle*4.0f);
g_pLogfile->FunctionResult("Funktion_Eins", L_OK);
g_pLogfile->FunctionResult("Funktion_Zwei", L_FAIL);
g_pLogfile->Del();
return 0;
}
|
Der Compilerfehler:
1>c:\users\alexander\documents\visual studio 2008\projects\listing_8\logfile_1.cpp(95) : error C2664: 'vsprintf': Konvertierung des Parameters 1 von 'TCHAR [1024]' in 'char *' nicht möglich
1> Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.
1>c:\users\alexander\documents\visual studio 2008\projects\listing_8\logfile_1.cpp(98/) : error C2664: 'void CLogfile::Textout(const char *)': Konvertierung des Parameters 1 von 'TCHAR [1024]' in 'const char *' nicht möglich
1> Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.
1>c:\users\alexander\documents\visual studio 2008\projects\listing_8\logfile_1.cpp(107) : error C2664: 'vsprintf': Konvertierung des Parameters 1 von 'TCHAR [1024]' in 'char *' nicht möglich
1> Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.
1>c:\users\alexander\documents\visual studio 2008\projects\listing_8\logfile_1.cpp(110) : error C2664: 'void CLogfile::Textout(int,const char *)': Konvertierung des Parameters 2 von 'TCHAR [1024]' in 'const char *' nicht möglich
1> Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.
1>c:\users\alexander\documents\visual studio 2008\projects\listing_8\logfile_1.cpp(119) : error C2664: 'vsprintf': Konvertierung des Parameters 1 von 'TCHAR [1024]' in 'char *' nicht möglich
1> Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.
1>c:\users\alexander\documents\visual studio 2008\projects\listing_8\logfile_1.cpp(122) : error C2664: 'void CLogfile::Textout(int,bool,const char *)': Konvertierung des Parameters 3 von 'TCHAR [1024]' in 'const char *' nicht möglich
1> Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.