title: Undefined reference with multiple files in C++
body: <p>I created this small program using multiple files, I removed most of the class members for simplicity</p>
  <p>Program Description:</p>
  <ul>
  <li><p>Class <strong>User</strong> has a <strong>service</strong> member object</p>
  </li>
  <li><p><strong>Service</strong> class contains one member function to perform string splitting</p>
  </li>
  <li><p>Class <strong>User</strong> uses the <strong>stringSplitter</strong> member function from <strong>Service</strong> class</p>
  </li>
  <li><p><strong>main()</strong> is empty, I just wanted to test the program</p>
  </li>
  </ul>
  <p>I have the following error (when I try to build and run):</p>
  <p><strong>undefined reference to `Service::stringSplitter</strong></p>
  <p>How can I solve it?</p>
  <p><strong>Here is my code:</strong></p>
  <p>User.h</p>
  <pre><code>#ifndef USER_H_INCLUDED
  #define USER_H_INCLUDED
  #include &lt;bits/stdc++.h&gt;
  #include &quot;Service.h&quot;
  using namespace std;
  
      class User
      {
      public:
          User ();
          User (const string &amp;);
          Service getService ();
      
      private:
      
          Service generalService;
      
      };
      
      
      #endif // USER_H_INCLUDED
  </code></pre>
  <p>User.cpp</p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  #include &quot;User.h&quot;
  using namespace std;
  
  User :: User (const string &amp;str)
  {
      vector &lt;string&gt; pieces = getService().stringSplitter (str, ',');
  
  }
  Service User :: getService ()
  {
      return generalService;
  }
  </code></pre>
  <p>Service.h</p>
  <pre><code>#ifndef SERVICE_H
  #define SERVICE_H
  #include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  class Service
  {
  public:
      vector &lt;string&gt; stringSplitter (string s, char delimiter);
  
  };
  
  #endif // SERVICE_H
  </code></pre>
  <p>Service.cpp</p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  #include &quot;Service.h&quot;
  using namespace std;
  
  vector &lt;string&gt; stringSplitter (string s, char delimiter)
  {
      vector &lt;string&gt; vec;
      string x;
      for (int i = 0; i &lt; (int) s.length(); i++)
      {
          x += s[i];
          if (s[i] == delimiter)
          {
              x.erase (x.length() - 1, 1);
              vec.push_back (x);
              x.clear();
         }
      }
      return vec;
  }
  </code></pre>