Menu

Why does OstreamAppender take ptr to ostream?

Help
Marc Pound
2003-02-10
2003-02-13
  • Marc Pound

    Marc Pound - 2003-02-10

    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

     
    • Marc Pound

      Marc Pound - 2003-02-12

      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

       
    • Bastiaan Bakker

      Bastiaan Bakker - 2003-02-13

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.