Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your immediate problem is that you try to pass a temporary <code>streamAggrator</code> object to a function which takes a <code>streamAggrator</code> by non-<code>const</code> reference. You can't bind temporary object to non-<code>const</code> references. The work-around for this problem is to make the output operator member of your <code>streamAggrator</code>: while you cannot bind a temporary to a non-<code>const</code> reference, you <em>can</em> call non-<code>const</code> member functions. Note that you'll also get problems with maniputors like <code>std::flush</code> (the issue there is that these are templates themselves and you actually need to a concrete operator to call them with to have the compiler deduce their template arguments).</p> <p>Clearly, I would solve the problem properly, i.e., instead of trying to dig about an attempt to a solution which doesn't create a stream, I would create a <code>std::streambuf</code> do do the actual work. Your examples doesn't do anything useful, i.e., I can't really tell what you are trying to do but the code looks remarkably like trying to do something like <code>teestream</code>: write once but send the output to multiple destintations. I have posted corresponding stream buffers quite a few times in the post (mostly on Usenet, though, but I think, at least, once on Stackoverflow, too).</p> <p>Although I don't know how to get rid of the macro to fill in the <code>__FILE__</code> and the <code>__LINE__</code>, the actual stream formatting should probably use a stream buffer:</p> <pre><code>struct teebuf: std::streambuf { private: std::streambuf* sb1; std::streambuf* sb2; public: teebuf(std::streambuf* sb1, std::streambuf* sb2): sb1(sb1), sb2(sb2) {} int overflow(int c) { this-&gt;sb1-&gt;sputc(c); this-&gt;sb2-&gt;sputc(c); return std::char_traits&lt;char&gt;::not_eof(c); } int sync() { this-&gt;sb1-&gt;pubsync(); this-&gt;sb2-&gt;pubsync(); } }; class logstream : std::ostream { std::ofstream out; teebuf sbuf; public: logstream() : out("file.log") , sbuf(out.rdbuf(), std::clog.rdbuf()) { this-&gt;init(&amp;this-&gt;sbuf); } logstream(logstream&amp;&amp; other) : out(std::move(other.out)) , sbuf(std::move(other.sbuf)) { this-&gt;init(&amp;this-&gt;sbuf); }; </code></pre> <p>I <em>think</em> you can return the log stream. I don't know what your logging level is meant to do but I guess its processing was removed while preparing the question: it is probably necessary to change the implementation to take the logging level suitably into account.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload