Имеется следующий класс.
class Log: public ofstream
{
public:
Log(char* szLogFn=LOG_FILE);
~Log();
ofstream& operator<<(const char* szmsg);
ofstream& operator<<(int ival);
ofstream& operator<<(double dval);
private:
// ...
};
Log::Log(char* szLogFn): ofstream(szLogFn,ios_base::out)
{
this->szLogFn=new char[strlen(szLogFn)+1];
strcpy_s(this->szLogFn,strlen(szLogFn)+1,szLogFn);
InitializeCriticalSection(&csLog);
}
Log::~Log()
{
close();
delete[] szLogFn;
DeleteCriticalSection(&csLog);
}
ofstream& Log::operator<<(const char* szmsg)
{
EnterCriticalSection(&csLog);
ofstream::operator<<(szmsg);
flush();
LeaveCriticalSection(&csLog);
return *this;
}
ofstream& Log::operator<<(int ival)
{
EnterCriticalSection(&csLog);
ofstream::operator<<(ival);
flush();
LeaveCriticalSection(&csLog);
return *this;
}
ofstream& Log::operator<<(double dval)
{
EnterCriticalSection(&csLog);
ofstream::operator<<(dval);
flush();
LeaveCriticalSection(&csLog);
return *this;
}
Если в Log записывать числа, всё работает как надо, а для строк записывается опять число, и такое впечатление, что это адрес szmsg. Почему так происходит?