title: C++ warning: pragma once in main file
body: <p>I'm have an issue with compiling my program with g++ 8.3. I have approx 10 classes in a program. These classes are placed in header files and their full definitions are in <code>.cpp</code> files. I'm including these classes the same way as in this code:</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "CPerson.h"
  
  int main()
  {
      CPerson person1(10 , "Peter");
      CPerson person2(20 , "James");
      person1.Print();
      person2.Print();
      return 0;
  }
  </code></pre>
  
  <p>CPerson.h:</p>
  
  <pre><code>#pragma once
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class CPerson{
  protected:
      int m_Age;
      string m_Name;
  public:
      CPerson( const int age , const char * name ) :
      m_Age(age), m_Name(name){}
      void Print(){
          cout &lt;&lt; "Hello Im " &lt;&lt; m_Name &lt;&lt; " - " &lt;&lt; m_Age &lt;&lt; "years old" &lt;&lt; endl;
      }
  };
  </code></pre>
  
  <p>When I try to compile this C++ program with the following command:</p>
  
  <blockquote>
    <p>g++ main.cpp CPerson.h</p>
  </blockquote>
  
  <p>I get this message:</p>
  
  <blockquote>
    <p>warning: #pragma once in main file</p>
  </blockquote>
  
  <p>Is here anything I can do about this, or is it just bug in the g++ compiler?</p>
  
  <p><strong>SOLVED:</strong></p>
  
  <p>You need to compile only .cpp files with declarations of methods of each class thats defined in Class.h</p>