title: How to import a class in another C++ header file?
body: <p>I meet a problem when constructing a class. class "Graph" import a class "Bag" in another file and use "Bag" as its component. </p>
  
  <pre><code>//Graph.h
  #ifndef GRAPH_H
  #define GRAPH_H
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include "Bag.h"
  class Bag;
  class Graph
  {
  public:
      Graph(int V);
      Graph(std::ifstream&amp; in_file);
      int getV() { return V; }
      int getE() { return E; }
      void addEdge(int v, int w);
      void showadj() ;
  private:
      int V;
      int E;
      std::vector&lt;Bag&gt; adj;
  };
  #endif
  </code></pre>
  
  <p>And "Bag.h" is as follow:</p>
  
  <pre><code>//Bag.h
  #ifndef BAG_H
  #define BAG_H
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  class Bag
  {
  public: 
      Bag();
      void addBag(int i) { content.push_back(i); }
      void showBag();
  private:
      std::vector&lt;int&gt; content;
  };
  
  #endif 
  </code></pre>
  
  <p>Graph.cpp: </p>
  
  <pre><code>//Graph.cpp
  #include "Graph.h"
  #include "Bag.h"
  Graph::Graph(int V) : V(V), E(0)
  {
      for (int i = 0; i &lt; V; i++)
      {
          Bag bag;
          adj.push_back(bag);
      }
  }
  </code></pre>
  
  <p>Bag.cpp(sorry, forget it):</p>
  
  <pre><code>#include "Bag.h"
  void Bag::showBag()
  {
      for (int i : content)
      {
          std::cout &lt;&lt; i &lt;&lt; " ";
      }
  }
  </code></pre>
  
  <p>When I try to complie these two classes, an error comes out saying:</p>
  
  <pre><code>C:\Users\ADMINI~1\AppData\Local\Temp\ccMj4Ybn.o:newtest.cpp:(.text+0x1a2): undef
  ined reference to `Bag::Bag()'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>