title: Forward-declare typedef struct in c++
body: <p>I am using a legacy lib that defines a struct in Foo.h:</p>
  <blockquote>
  <p><code>typedef struct { int i; int j; } Foo</code></p>
  </blockquote>
  <p>However in my C++ program I am trying to write the following in a header file.</p>
  <pre><code>// forward-declare the struct
  struct Foo;
  
  class Bar {
    void myFunction(std::shared_ptr&lt;Foo&gt; foo);
  };
  </code></pre>
  <p>And in my cpp file:</p>
  <p><code>#include &quot;Foo.h&quot;</code></p>
  <p>However this fails with an error:</p>
  <blockquote>
  <p>typedef redefinition with different types ('struct Foo' vs 'Foo')</p>
  </blockquote>
  <p>What is the correct syntax to do this?</p>