title: ifndef with cpp file in new library
body: <p>Hello im trying to build my own library in c++, and after many hours of searching and trying i learnt that a good way of doing one would be using nested classes, so i made some code in this form of tree:
  <a href="https://i.stack.imgur.com/1lIux.png" rel="nofollow noreferrer">file tree</a></p>
  <p>So i divided all the class files into different header files(i know this is harder and maybe not necessary but i wanted have it like that, if nothing more then just for training). And so to keep the nested class connected, but in different files, each header needs to include its child and or parent to function correctly. This didnt work, gave me errors of recursive include (duh) so i searched online and found #ifndef and #define and i used them in this way:</p>
  <pre class="lang-cpp prettyprint-override"><code>    //A.hpp
      #ifndef A_HPP_INCLUDED   // some unique macro
      #define A_HPP_INCLUDED
  
      class A
      {
      public:
          class B;
          class C;
          
      };
      #include &quot;B.hpp&quot;
      #include &quot;C.hpp&quot;
      #endif
  
      //B.hpp
      #ifndef B_HPP_INCLUDED
      #define B_HPP_INCLUDED
  
      #include &quot;A.hpp&quot;
      class A::B
      {
      public:
          static int num;
          void func();
      };
      #endif
      int A::B num = 5;
  
      //C.hpp
      #ifndef C_HPP_INCLUDED   // some unique macro
      #define C_HPP_INCLUDED
  
      #include &quot;A.hpp&quot;
      class A::C
      {
      public:
          void func();
      };
      #endif
  </code></pre>
  <p>But the second i add #include &quot;B.hpp&quot; into the B.cpp file it immediately gives me error that all variables and functions ive added in this way are defined multiple times. Without cpp files it works perfectly, but with them it crashes. In fact this happens when adding any cpp file to any header</p>
  <p>Answers to this problem are welcome, but if you have any tips on how to make library files in a better way or even just random tips, thatd be awesome!</p>
  <p>fyi im using qt creator, qmake, c++11. if qmake file is needed ill send it but i think everything there is good.</p>
  <p>The files in question (for reproducing the problem):</p>
  <pre class="lang-cpp prettyprint-override"><code>    //testlibrary.hpp
  
      #ifndef TESTLIBRARY_HPP_INCLUDED   // some unique macro
      #define TESTLIBRARY_HPP_INCLUDED
  
      class TestLibrary
      {
      public:
          class Core;
          class SFML;
      };
      #include &lt;Core/Core.hpp&gt;
      #include &lt;SFML++/SFMLpp.hpp&gt;
      #endif
  
  
      //Core.hpp
      #pragma once
  
      #ifndef CORE_HPP_INCLUDED   // some unique macro
      #define CORE_HPP_INCLUDED
  
      #include &lt;testlibrary.hpp&gt;
  
      class TestLibrary::Core
      {
      public:
          class Constants;
      };
      #include &quot;Constants.hpp&quot;
      #endif
  
  
      //Constants.hpp
      #pragma once
      #ifndef CONSTANTS_HPP_INCLUDED   // some unique macro
      #define CONSTANTS_HPP_INCLUDED
      #include &quot;Core.hpp&quot;
      class TestLibrary::Core::Constants
      {
      public:
          static float const_PI;
          static float const_Euler;
          Constants();
      };
      float TestLibrary::Core::Constants::const_PI = 3.1415;
      float TestLibrary::Core::Constants::const_Euler = 2.71828;
      #endif
  
  
      //SFMLpp.hpp
      #pragma once
      #include &lt;SFML/Window.hpp&gt;
      #include &lt;SFML/Graphics.hpp&gt;
      #ifndef SFML_HPP_INCLUDED   // some unique macro
      #define SFML_HPP_INCLUDED
      #include &lt;testlibrary.hpp&gt;
      class TestLibrary::SFML
      {
      public:
          class Text;
      };
  
      //#include &quot;Text.hpp&quot;
      #endif
  
  
      //Text.hpp
      #pragma once
  
      #ifndef TEXT_HPP_INCLUDED   // some unique macro
      #define TEXT_HPP_INCLUDED
      #include &quot;SFMLpp.hpp&quot;
      class TestLibrary::SFML::Text : public sf::Text
      {
      public:
          sf::Font font_;
  
          Text();
          Text(std::string string);
          Text(std::string string, sf::Font &amp;font);
          Text(std::string string, sf::Font &amp;font, int size);
          Text(std::string string, sf::Font &amp;font, int size, sf::Color color);
  
          void setTextInt(int inputText);
          void drawText(sf::RenderWindow &amp;window);
      };
  
      #endif
  
  
      //text.cpp
      #include &quot;text.hpp&quot;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/jF3Tm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jF3Tm.png" alt="The error messages" /></a></p>