Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a couple of issues with your templates, the first is that both differ only on the reference, and that will cause issues. You only want one (that reads and does not write to the argument):</p> <pre><code> template&lt;class T&gt; friend logger &amp; operator&lt;&lt;(logger&amp; log, const T &amp; bytes); // ^^^^^ </code></pre> <p>Now the second problem is that the templates should be defined somewhere where the compiler can see it when generating the instantiation. That basically means that the definition must be in the header, not in the .cpp file. <sup>[*]</sup></p> <p>Beyond that, since the <code>logger</code> type is private to <code>ProblemsManager</code>, you cannot access it from the namespace level, so you will have issues defining the free function, since it cannot access the nested type. The options would be making the type public, making the function also a friend of <code>ProblemsManager</code>, or as I would recommend, just define the template inline inside the class definition:</p> <pre><code>class ProblemsManager { private: class logger { template&lt;class T&gt; friend logger &amp; operator&lt;&lt;(logger&amp; log, T &amp; bytes) { // implementation goes here } }; }; </code></pre> <hr> <p><sup>[*]</sup> This might actually be the exception to the rule, since being a private type, I can only assume that all uses of the <code>logger</code> and thus the <code>operator&lt;&lt;</code> will happen within the translation unit that defines <code>ProblemsManager</code> members. If that is the case, you can disregard this paragraph.</p>
 

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