title: how can we compile and run multiple .h and .cpp and one main.cpp file together
body: <p>I have created a Card.h file having a class card, I need this Class in Deck.cpp. The class Deck is needed in Hand class Implementation.
  These are the files</p>
  <pre><code>#ifndef CARD_H
  #define CARD_H
  #include&lt;utility&gt;
  class Card{
  // a card have a suit and a rank
  // we can create a pair of string
  public:
      std::pair&lt;std::string,std::string&gt; card ;    
  public:
  Card(){
  
  }
  Card(std::string r, std::string s){
      card = std::make_pair(s,r);
  }
  };
   class Deck{
  // we can create a vector of Card type
  public:
      vector&lt;Card&gt; deck;
  public: 
  Deck();
  };
  class Hand{
  //this class will hold what card a players get
  vector&lt;Card&gt; hand; // it will have 5 cards
  public:
      Hand();
      Hand(Deck cards,int start,int end);
      void displayHand();
  };
  
  
  #endif
  </code></pre>
  <p>Deck.cpp</p>
  <pre><code>#include&lt;bits/stdc++.h&gt;
  #include&lt;vector&gt;
  #include&lt;string&gt;
  #include&lt;chrono&gt;
  #include &quot;card.h&quot;
  using namespace std;
  class Deck{
      // we can create a vector of Card type
      public:
          vector&lt;Card&gt; deck;
      public: 
      Deck(){
          string suits[4] = {&quot;hearts&quot;,&quot;spade&quot;,&quot;clubes&quot;,&quot;diamonds&quot;};
          string rank[14] = {&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;,&quot;Joker&quot;,&quot;Queen&quot;,&quot;King&quot;,&quot;Ace&quot;};
          for( int  i =0 ; i&lt;4 ; i++){
              for(int j =0 ;j&lt;14;j++){
                  Card temp(suits[i],rank[j]); // using the constructor function 
                  deck.push_back(temp);
              }
          }
          //after taking all values we need to shuffle the elements of our vector
          // for this what one can do is to 
          // run a loop through our vector deck generate a random number between 0 and 52-1 and swap the ith element with that random index
          // here I am using the built in shuffle function in C++
          unsigned seed = std::chrono::system_clock::now()
                          .time_since_epoch()
                          .count();
          shuffle(deck.begin(),deck.end(),default_random_engine(seed));
          
      }
  };
  </code></pre>
  <p>Hand.cpp file</p>
  <pre><code>#include&lt;bits/stdc++.h&gt;
  #include&lt;vector&gt;
  #include&lt;string&gt;
  #include&quot;card.h&quot;
  using namespace std;
  class Hand{
  
      //this class will hold what card a players get
      vector&lt;Card&gt; hand; // it will have 5 cards
      public:
          Hand(){
  
          }
          Hand(Deck cards,int start,int end){ // we will slice 5 cards from Deck of cards and give it here
              for(int i = start ; i&lt; end ;i++){
                  hand.push_back(cards.deck[i]);
              }
          }
          void displayHand(){
              for(int  i = 0 ; i&lt; hand.size() ; i++){
                  cout&lt;&lt;hand[i].card.first &lt;&lt;&quot; &quot;&lt;&lt;hand[i].card.second&lt;&lt;endl;
              }
          }
  };
  </code></pre>
  <p>Main.cpp file</p>
  <pre><code>#include&lt;bits/stdc++.h&gt;
  #include&lt;utility&gt;
  #include&lt;vector&gt;
  #include&lt;string&gt;
  #include&quot;card.h&quot;
  using namespace std;
  
  int main(){
      Deck d;
      Hand p1(d,0,5);
      Hand p2(d,5,10);
      Hand p3(d,10,15);
      Hand p4(d,15,20);
      Hand p5(d,20,25);
      p1.displayHand();
      p2.displayHand();
      p3.displayHand();
      p4.displayHand();
      p5.displayHand();
  
  }
  </code></pre>
  <p>I know that the best practice is to use .h files for classes. But I want to know how we can do this in this way.
  for compiling I am using g++ *.cpp -o program</p>
  <hr />
  <p>and it is giving me the following errors</p>
  <pre><code>    In file included from deck.cpp:5:
      card.h:20:9: error: ‘vector’ does not name a type
      20 |         vector&lt;Card&gt; deck;
          |         ^~~~~~
      card.h:27:5: error: ‘vector’ does not name a type
      27 |     vector&lt;Card&gt; hand; // it will have 5 cards
          |     ^~~~~~
      deck.cpp:7:11: error: redefinition of ‘class Deck’
          7 |     class Deck{
          |           ^~~~
      In file included from deck.cpp:5:
      card.h:17:8: note: previous definition of ‘class Deck’
      17 |  class Deck{
          |        ^~~~
      In file included from hand.cpp:4:
      card.h:20:9: error: ‘vector’ does not name a type
      20 |         vector&lt;Card&gt; deck;
          |         ^~~~~~
      card.h:27:5: error: ‘vector’ does not name a type
      27 |     vector&lt;Card&gt; hand; // it will have 5 cards
          |     ^~~~~~
      hand.cpp:6:11: error: redefinition of ‘class Hand’
          6 |     class Hand{
          |           ^~~~
      In file included from hand.cpp:4:
      card.h:24:7: note: previous definition of ‘class Hand’
      24 | class Hand{
          |       ^~~~
      In file included from main.cpp:5:
      card.h:20:9: error: ‘vector’ does not name a type
      20 |         vector&lt;Card&gt; deck;
          |         ^~~~~~
      card.h:27:5: error: ‘vector’ does not name a type
      27 |     vector&lt;Card&gt; hand; // it will have 5 cards
          |     ^~~~~~
  </code></pre>