title: c++ " undefined reference to 'Foo::Foo(std::string)' "
body: <p>I'm not too familiar with c++ and how instantiating objects work, so this is probably a very simple thing to solve.  When I compile with g++ I get the error " undefined reference to 'Foo::Foo(std::string)' ".  I want to create an instance of the class Foo that has a string parameter in its constructor.  Here is the code:</p>
  
  <h2>Foo.h</h2>
  
  <pre><code>#include &lt;string&gt;
  using namespace std;
  
  class Foo
  {
      public:
          Foo(string s);
  
      private:
          string id;
  };
  </code></pre>
  
  <h2>Foo.cpp</h2>
  
  <pre><code>#include &lt;string&gt;
  #include "Foo.h"
  using namespace std;
  
  Foo::Foo(string s)
  {
      id = s;
  }
  </code></pre>
  
  <h2>main.cpp</h2>
  
  <pre><code>#include &lt;string&gt;
  #include "Foo.h"
  using namespace std;
  
  int main()
  {
      Foo foo("bar");
  
      return 0;
  }
  </code></pre>