Can you show me the definitions of writeLog? Because it seems to me you're going about this in a funky way.
Edit: Unless, of course, you're trying to wrap and simulate a stream, where something like this is appropriate:
#include <iostream>
#include <string>
using namespace std;
class Header {
string _date;
string _name;
public:
Header(const string& date, const string& name)
: _date(date), _name(name) {}
friend ostream& operator<<(ostream& out, const Header& h )
{
return out<< h._date <<" -- "<< h._name <<'\n';
}
};
class Log {
ostream& _out;
Header _header;
bool _first;
public:
Log(const Header& header, ostream& out = cout)
: _header(header), _out(out), _first(true) {};
ostream& operator<<(const string& s)
{
if (_first) {
_out<< _header <<'\n';
_first = false;
}
return _out<< s;
}
};
int main()
{
Log log(Header("05-05-2005", "Narue's Log"));
log<<"This is a test"<<endl;
log<<"Another test"<<endl;
log<<"Last test"<<endl;
}
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004