Здравствуйте, cs_student, Вы писали:
_>Здравствуйте, Chorkov, Вы писали:
C>>Рискну посоветовать использовать:
C>>C>>class Log: public ofstream
C>>{
C>>public:
C>> Log(char* szLogFn);
C>> ~Log();
C>> template<class C>
C>> Log& operator<<(const C& c)
C>> {
C>> EnterCriticalSection(&csLog);
C>> static_cast<ofstream&>(*this) << c;
C>> flush();
C>> LeaveCriticalSection(&csLog);
C>> return *this;
C>> }
C>>private:
C>>};
C>>
_>Тогда компилятор говорит "error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)".
Проверял на VS2005 следующем примере:
#include <iostream>
#include <fstream>
using namespace std;
class Log: private ofstream
{
public:
Log(char* szLogFn);
~Log();
template<class C>
Log& operator<<(const C& c)
{
static_cast<ofstream&>(*this) << c;
return *this;
}
private:
};
Log::Log(char* szLogFn): ofstream(szLogFn,ios_base::out)
{}
Log::~Log()
{}
int main()
{
Log a("c:\\log");
a<<"1";
a<<" "<<2;
a<<"\t"<<1.1<< " ";
}
Все работало
1) какой компилятор?
2) используем ли ты fastream из <fstream> или устаревший из <fstream.h> ?
3) на аргументе какого типа выдается это сообщение об ошибке ?