title: Creating a struct and a class with the same name
body: <p><strong>Summary</strong>: What happens if you declare a <code>struct</code> and a <code>class</code> with the same name.</p>
  
  <p><strong>Details</strong>:</p>
  
  <p>I'm reviewing some code and I saw a warning like this:</p>
  
  <pre><code>warning: struct 'foo' was previously declared as a class
  </code></pre>
  
  <p>When compiling with clang there were also a couple of places where clang added notes saying:</p>
  
  <pre><code>foo.h:29:1: note: did you mean struct here?
  class foo;
  ^~~~~
  struct
  </code></pre>
  
  <p>Obviously this is not a good coding practice to have a struct and a class with the same name.  It looks like what happened is the developer was writing his own class and used a name that was already in use in another file that he was including and he did not notice that.</p>
  
  <p>However, my question is will the compiler be able to tell the difference between the variables that were declared as <code>class foo</code> and the ones that were <code>struct foo</code>?</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Actually what was happening was that the developer was using the <code>class foo</code> in a <code>class bar</code> that he had created.  I think that in the meantime the place where the <code>class foo</code> was declared had been changed to a <code>struct bar</code>.  So that was why the code was compiling.  So I guess the answer to my question is that <code>struct</code> and <code>class</code> are interchangeable when declaring objects.  Still I guess it's a good idea to use them consistently.</p>