title: Friend function that takes 2 classes in parameters - 'Class' not defined
body: <p>I encountered some issues while working on friend functions. I want to use a friend function that uses two different classes in parameters. Here is the sample of code:</p>
  
  <p>ObjectA.h:</p>
  
  <pre><code>#ifndef OBJECTA_H_
  #define OBJECTA_H_
  
  #include "ObjectB.h"
  
  #include &lt;iostream&gt;
  using namespace std;
  
  class ObjectA {
  private:
      friend void friendFunction(ObjectA &amp;,ObjectB &amp;);
  
  public:
      ObjectA();
      virtual ~ObjectA();
  };
  
  #endif /* OBJECTA_H_ */
  </code></pre>
  
  <p>ObjectB.h:</p>
  
  <pre><code>#ifndef OBJECTB_H_
  #define OBJECTB_H_
  
  #include &lt;iostream&gt;
  using namespace std;
  
  #include "ObjectA.h"
  
  class ObjectB {
  private:
      friend void friendFunction(ObjectA &amp;, ObjectB &amp;);
  
  public:
      ObjectB();
      virtual ~ObjectB();
  };
  
  #endif /* OBJECTB_H_ */
  </code></pre>
  
  <p>Both .cpp files for ObjectA and ObjectB are empty (empty constructor and destructor). Here is the main .cpp file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  #include "ObjectA.h"
  #include "ObjectB.h"
  
  void friendFunction(ObjectA &amp;objA, ObjectB &amp;objB){
      cout &lt;&lt; "HIIIIIIIIIII";
  }
  
  int main() {
      cout &lt;&lt; "!!!Hello World!!!" &lt;&lt; endl; // prints !!!Hello World!!!
  
      return 0;
  }
  </code></pre>
  
  <p>This all thing sends me the following error :</p>
  
  <pre><code>'ObjectA' has not been declared
  </code></pre>
  
  <p>And this error is pointing to this line in the ObjectB.h :</p>
  
  <pre><code>friend void friendFunction(ObjectA &amp;, ObjectB &amp;);
  </code></pre>
  
  <p>As you can see, the ObjectA.h file has been included in the ObjectB.h file. So I don't know where my error come from.</p>
  
  <p>Maybe I'm using friend function in a wrong way ?</p>
  
  <p>Thank you guys !</p>