title: Forward declaration as struct vs class
body: <p>I found a mistake in a C++ forward declaration of a class, which was wrongly declared as <code>struct Book</code> instead of <code>class Book</code>. I think Book used to be a struct, got changed to a class but the forward declarations remained.</p>
  <p>Book.h:</p>
  <pre><code>class Book {
      ...
  };
  </code></pre>
  <p>Library.h:</p>
  <pre><code>struct Book;
  
  class Library {
      std::vector&lt;Book*&gt; books;
  };
  </code></pre>
  <p>There were no compiler warnings and the resulting program seemed to work fine. It made me curious: <strong>in theory, can this ever cause a problem?</strong> It's just a pointer, yes, but for example, if the class had virtual methods, multiple inheritance, could the pointers be different?</p>
  <p>I know the differences between class/struct regarding default public/private but I'm asking specifically about the forward declarations and possible consequences of swapping them.</p>
  <p><strong>UPDATE</strong> newer versions of Xcode now give this warning when there's a mismatch:</p>
  <pre><code>Struct 'Book' was previously declared as a class; this is valid, but may result in linker errors under the Microsoft C++ ABI
  </code></pre>