title: Circular Dependency - (how to let struct A refer to struct B, and struct B refer to struct A)
body: <p>I have a header file with a struct called Vector4.</p>
  
  <p>(vector4.h)</p>
  
  <pre><code>struct Vector4
  {
      float Values[4];
  
      // ..... methods .....
  };
  </code></pre>
  
  <p>I have a header file with a struct called Matrix4.</p>
  
  <p>(matrix4.h)</p>
  
  <pre><code>struct Matrix4
  {
      float Values[16];
  
      // ..... methods .....
  };
  </code></pre>
  
  <p>I want to add a member function to them both, say multiply() which takes the other struct as a parameter.</p>
  
  <p>I can easily add matrix4.h to vector4.h and add the method multiply().</p>
  
  <p>If I then try and add vector4.h to matrix4.h I (obviously) will get a circular reference.</p>
  
  <p>How can I get around this please, if at all?</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>@MikeSeymour, I have written what I assumed you meant, but it doesn't work.</p>
  
  <p>bar.h</p>
  
  <pre><code>#ifndef BAR_H
  #define BAR_H
  
  template &lt;typename T&gt;
  struct Foo;
  
  template &lt;typename T&gt;
  struct Bar
  {
      T t;
  
      T multiply(const Foo&lt;T&gt;&amp; foo) const;
  };
  
  #endif // BAR_H
  </code></pre>
  
  <p>foo.h</p>
  
  <pre><code>#ifndef FOO_H
  #define FOO_H
  
  template &lt;typename T&gt;
  struct Bar;
  
  template &lt;typename T&gt;
  struct Foo
  {
      T t;
  
      T multiply(const Bar&lt;T&gt;&amp; bar) const;
  };
  
  #endif // FOO_H
  </code></pre>
  
  <p>bar.cpp</p>
  
  <pre><code>#include "foo.h"
  #include "bar.h"
  
  Bar&lt;T&gt;::multiply(const Foo&lt;T&gt;&amp; foo) const
  {
      return t * foo.t;
  }
  </code></pre>
  
  <p>foo.cpp</p>
  
  <pre><code>#include "foo.h"
  #include "bar.h"
  
  Foo&lt;T&gt;::multiply(const Bar&lt;T&gt;&amp; bar) const
  {
      return t * bar.t;
  }
  </code></pre>