Note that there are some explanatory texts on larger screens.

plurals
  1. POIn what cases do global operators get hidden in C++?
    primarykey
    data
    text
    <p>I'm rearranging the namespaces of code in relatively large C++ project. One difficulty I keep running into is that global operator overloads become inaccessible sometimes. Things like stream operators (&lt;&lt; and >>) and equality operators (==), Sometimes the only changes that cause this is moving from say "namespaceA" to "parent::namespaceA". Namespace "parent" already exists.</p> <p>I can fix these by explicitly adding:</p> <pre><code>using ::operator&lt;&lt;; using ::operator&gt;&gt;; using ::operator==; </code></pre> <p>in the affected files (from "namespaceA"), although I was somewhat surprised to see this work.</p> <p>But this feels like I'm just masking a deeper problem somewhere.</p> <p>So my question is this: <strong>What situations would you expect the masking/hiding of global operators to occur?</strong></p> <p>Note: I suspected it might be the nested namespaces prevent Koenig Lookup doing its thing, but making some test cases showed this wasn't the issues. Another potentially salient point is that the overloaded global operators affected seem to all be templated functions. However, I'm interested in better understanding how the global namespace operators somehow disappear... all answers appreciated.</p> <p>Clearly it's something to do with the parent namespace, but I'm not entirely sure what I'm looking for. I can understand an operator being overloaded again so that the wrong version is called, but I'm getting compile errors that can't even find the operators with the right signature!</p>
    singulars
    1. This table or related slice is empty.
    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. 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