title: How to overload the operator<< from within a namespace
body: <p>This is the smallest contained example I can think of.
  First the header of the class. This class should simply print the one double it contains whenever the &lt;&lt; operator is used.</p>
  
  <pre><code>#pragma once
  #ifndef EURO_H
  #define EURO_H
  
  #include &lt;ostream&gt;
  
  namespace EU
  {
     class Euro final
     {
     public:
          explicit Euro(double value);
          virtual ~Euro() = default;
  
          double getValue() const;
  
          friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, const Euro &amp;euro);
  
      private:
          double m_value;
      };
  }
  
  #endif // EURO_H
  </code></pre>
  
  <p>Now the .cpp</p>
  
  <pre><code>#include "euro.h"
  
  using namespace EU;
  
  Euro::Euro(double value)
  {
      m_value = value;
  }
  
  double Euro::getValue() const
  {
      return m_value;
  }
  
  std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, const Euro &amp;euro)
  {
      os &lt;&lt; euro.getValue() &lt;&lt; "EUR";
      return os;
  }
  </code></pre>
  
  <p>And finally, the main.cpp</p>
  
  <pre><code>#include "euro.h"
  
  #include &lt;iostream&gt;
  
  using namespace EU;
  
  int main()
  {
      auto e = Euro(3.14);
      std::cout &lt;&lt; e &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>However, when I compile this using:</p>
  
  <pre><code>g++ -std=c++11 *.cpp
  </code></pre>
  
  <p>it spits out the following error:</p>
  
  <pre><code>/tmp/ccP7OKC5.o: In function `main':
  main.cpp:(.text+0x35): undefined reference to `EU::operator&lt;&lt;(std::ostream&amp;, EU::Euro const&amp;)'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Kind regards,
  Joris</p>