I'm trying to instantiate an OstreamAppender that directs its
messages to cout. However, since the constructor takes
an ostream* rather than an ostream&, this is difficult to do.
Methods in iostream.h only return references, so you can't
create an ostream* from an ostream&.
Why is the _stream member in OstreamAppender a pointer
instead of a reference?
Marc
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Per convention passing a pointer should imply that the Appender takes ownership of the ostream object, which it doesn't.....
So I agree, OstreamAppenders behaviour is not correct.
However, it may make more sense to fix this by giving ostream ownership to the Appender, because in almost all cases you don't want to think anymore about the ostream after you've passed it to the Appender.
Cheers,
Bastiaan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to instantiate an OstreamAppender that directs its
messages to cout. However, since the constructor takes
an ostream* rather than an ostream&, this is difficult to do.
Methods in iostream.h only return references, so you can't
create an ostream* from an ostream&.
Why is the _stream member in OstreamAppender a pointer
instead of a reference?
Marc
Duh, this works:
OstreamAppender* oapp = new OstreamAppender("Debugger", &std::cout);
My problem was apparently due to log4cpp being compiled against an old kernel. But I still think _stream should be a reference!
Marc
Hi Marc,
Per convention passing a pointer should imply that the Appender takes ownership of the ostream object, which it doesn't.....
So I agree, OstreamAppenders behaviour is not correct.
However, it may make more sense to fix this by giving ostream ownership to the Appender, because in almost all cases you don't want to think anymore about the ostream after you've passed it to the Appender.
Cheers,
Bastiaan