title: Is it possible to define classes with same name in same namespace but in different nested projects?
body: <p>I have one big project in Eclipse, which contains multiple nested projects. Each one of those nested projects is in a separate folder and is compiled and linked separately. At the end, each one of them outputs a separate static library. Then there are few executables which are linked against those static libraries. In two of these projects I have two classes with the same name and same constructor arguments, but they have different implementations and also different extra members. Both classes are in the same namespace. After I compile each project I use the static libraries which they have created for a separate executables. Each executable is linked against the correct class, they don't mix implementations. Everything seems to work fine.</p>
  
  <p>The problem is that when I compile one of the classes, the compiler gives me an error that I haven't initialized some member variables, which actually belong to the other class. During compilation those classes don't have an access to each other - they don't include the other one or they don't include headers, which then include the other one. They are in separate projects, in separate folders and are compiled separately. How is then possible that when compiling the first class the compiler somehow looks for the definition of the second class and gives me an error that I haven't initialized a member from it? Since I am using Eclipse and my projects' structure is like this: Main C++ Project (which is not compiled) holds the other C++ projects as nested projects (which are compiled separately) inside it - is it possible that this is something related to Eclipse? </p>
  
  <p>Am I violating the One Definition Rule, since my classes are in separate projects and they are compiled in separate compilations, only having some common header files and no other connection between them? And if so, how is it possible that the compiler catches such an issue but it is still able to get the correct class definition? Because for sure it gets it right and everything works fine.</p>
  
  <p>So my problem is the warning that the compiler gives me, because I have to clean all compilation warning before shipping the code. The code itself works fine.</p>
  
  <p>Best Regards</p>
  
  <p>=== Update After Comments ===</p>
  
  <p>First of all, apologies for not being clear. 
  Here is an image of the whole Project structure (I have changed the names obviously :) ):</p>
  
  <p><a href="https://i.stack.imgur.com/NO6if.png" rel="nofollow noreferrer">The structure of my project</a></p>
  
  <p>I have the MainProject project, which acts as a container for the other projects. I don't build it. In <strong>nested1</strong> I have projects which make static libraries, which I then link with the Executable1 and Executable2. In <strong>nested2</strong> I have other projects which again make static libraries, which I then link with the Executable3. </p>
  
  <p>I have the MyFooBar class in both nested1 and nested2. Here is the code for both of them</p>
  
  <pre class="lang-cpp prettyprint-override"><code>// nested1/StaticLib5/MyFooBar.hpp
  namespace foo
  {
      namespace bar
      {
          class MyFooBar : public FooBar
          {
              public:
                     MyFooBar(int a, int b, double c);
                     // Getters and Setters
                     // Other user-defined functions
              private:
                     int memA;
                     int memB;
                     double memC;
                     int memDiff1;
          };
      }
  }
  </code></pre>
  
  <pre class="lang-cpp prettyprint-override"><code>// nested2/StaticLib9/MyFooBar.hpp
  namespace foo
  {
      namespace bar
      {
          class MyFooBar : public FooBar
          {
              public:
                     MyFooBar(int a, int b, double c);
                     // Getters and Setters
                     // Other user-defined functions
              private:
                     int memA;
                     int memB;
                     double memC;
                     int memDiff2;
                     char memDiff3;
  
          };
      }
  }
  </code></pre>
  
  <pre class="lang-cpp prettyprint-override"><code>// nested1/StaticLib5/MyFooBar.cpp
  namespace foo
  {
      namespace bar
      {
          MyFooBar::MyFooBar(int a, int b, double c) :
          memA{a}, memB{b}, memC{c}, memDiff1{0}
          {
          }         
      }
  }
  </code></pre>
  
  <pre class="lang-cpp prettyprint-override"><code>// nested2/StaticLib9/MyFooBar.cpp
  namespace foo
  {
      namespace bar
      {
          MyFooBar::MyFooBar(int a, int b, double c) :
          memA{a}, memB{b}, memC{c}, memDiff2{0}, memDiff3{0}
          {
          }         
      }
  }
  </code></pre>
  
  <p>Executable1 and Executable2 don't use any of the libraries in <strong>nested2</strong>. Executable3 uses the only the static library StaticLib1 <strong>nested1</strong>. </p>
  
  <p>Non of the Executables is linked to both StaticLib5 and StaticLib9. Also, I don't get an error during the linking of the executables, I get warning when compiling any of the MyFooBar classes. The warning says:</p>
  
  <pre><code>Member memDiff2 was not initialized in this constructor
  </code></pre>
  
  <p>The only thing that might be common for both classes is one header, where I have a class forward declaration and some typedefs, which I don't use in the class itself.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class MyFooBar;
  typedef ListWidget* MyFooBarPtr;
  typedef std::vector&lt; MyFooBarPtr &gt; MyFooBarVec;
  typedef MyFooBarVec* MyFooBarVecPtr;
  </code></pre>