title: undefined reference to operator<<
body: <p>I have a regular class (not a template, that is) with a private friend operator&lt;&lt;</p>
  
  <p>it's declaration is:</p>
  
  <pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Position&amp; position);
  </code></pre>
  
  <p>in the cpp file it's definition is:</p>
  
  <pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Position&amp; position)
  {
    out &lt;&lt; position.getXPoint() &lt;&lt; "," &lt;&lt; position.getYPoint();
    return out;
  }
  </code></pre>
  
  <p>it is being compiled then linked to the main function which uses it, however when I use it I get an undefined reference...</p>
  
  <p>however when I add the definition to the top of the main cpp file and remove the friend declaration, it works fine...</p>
  
  <p>heres how I am using it in my main function</p>
  
  <pre><code>std::cout &lt;&lt; node-&gt;getPosition() &lt;&lt; std::endl;
  </code></pre>
  
  <p>no more no less...</p>
  
  <p>heres the linker error</p>
  
  <blockquote>
    <p>/home/luke/Desktop/pathfinder/parse_world.cpp:34: undefined reference to `pathfinder::operator&lt;&lt;(std::ostream&amp;, pathfinder::Position const&amp;)'</p>
  </blockquote>
  
  <p>and heres the class header...</p>
  
  <pre><code>#ifndef PATHFINDER_H
  #define PATHFINDER_H
  #include &lt;ostream&gt;
  #include &lt;istream&gt;
  #include &lt;list&gt;
  #include &lt;vector&gt;
  #include &lt;stdexcept&gt;
  #include &lt;cstring&gt;
  namespace pathfinder
  {
  class Node;
  typedef unsigned int GCost;
  typedef std::vector&lt;std::vector&lt;Node*&gt; &gt; World;
  typedef std::vector&lt;Node*&gt; WorldRow;
  class Position
  {
  public:
      typedef unsigned int point_type;
  private:
      point_type* xPoint_;
      point_type* yPoint_;
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Position&amp; position);
  public:
      Position(const point_type&amp; xPoint = 0, const point_type&amp; yPoint = 0);
      Position(const Position&amp; position);
      Position(Position&amp;&amp; position);
      ~Position();
  
      Position&amp; operator=(const Position&amp; position);
      Position&amp; operator=(Position&amp;&amp; position);
  
      point_type getXPoint() const;
      point_type getYPoint() const;
  
      void setXPoint(const point_type&amp; xPoint);
      void setYPoint(const point_type&amp; yPoint);
  };
  class Node
  {
  private:
      bool* isPassable_;
      bool* isStartingNode_;
      bool* isTargetNode_;
      Position* position_;
      GCost* additionalGCost_;
      Node* parent_;
  public:
      Node(const bool&amp; isPassable = true, const bool&amp; isStartingNode = false, const bool&amp; isTargetNode = false, const Position&amp; position = Position(0,0), const GCost&amp; additionalGCost = 0, Node* parent = nullptr);
      Node(const Node&amp; node);
      Node(Node&amp;&amp; node);
      ~Node();
  
      Node&amp; operator=(const Node&amp; node);
      Node&amp; operator=(Node&amp;&amp; node);
  
      bool isPassable() const;
      bool isStartingNode() const;
      bool isTargetNode() const;
      Position getPosition() const;
      GCost getAdditionalGCost() const;
      Node* getParent() const;
  
      void setAsPassable(const bool&amp; isPassable);
      void setAsStartingNode(const bool&amp; isStartingNode);
      void setAsTargetNode(const bool&amp; isTargetNode);
      void setPosition(const Position&amp; position);
      void setAdditionalGCost(const GCost&amp; additionalGCost);
      void setParent(Node* parent);
  };
  class WorldHelper
  {
  public:
      static World fromStream(std::istream&amp; input);
      static void syncPositions(World&amp; world);
      static void uninitializeWorld(World&amp; world);
      static Node* findStartingNode(const World&amp; world);
      static Node* findTargetNode(const World&amp; world);
  };
  class Pathfinder
  {
  public:
      virtual std::list&lt;Node*&gt; operator()(World&amp; world) const = 0;
  };
  };
  #endif //PATHFINDER_H
  </code></pre>
  
  <p>now after removing the friend declaration I am getting error messages like:</p>
  
  <blockquote>
    <p>cannot bind ‘std::ostream {aka std::basic_ostream}’ lvalue to ‘std::basic_ostream&amp;&amp;’</p>
  </blockquote>
  
  <p>it is occuring on the same line as the std::cout statement...</p>
  
  <p>So, whats the deal...</p>
  
  <p>thanks in advance</p>