title: c++ friend function implemented in a class can't access privates
body: <p>I'm trying to define 2 classes, declare a friend function in one of them and implement it in the other.
  I am actually trying to get exactly what found in this post working:</p>
  
  <p><a href="https://stackoverflow.com/questions/1966255/how-can-friend-function-be-declared-for-only-one-particular-function-and-class">How can friend function be declared for only one particular function and class?</a></p>
  
  <p>I read the answer and thought it made sense.
  then implemented it in my code and it gave me the errors:</p>
  
  <p><strong>Edited:</strong></p>
  
  <p>Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup ...\MSVCRTD.lib(crtexe.obj) - <em>(solved by adding main function)</em></p>
  
  <p>Error 2 error LNK1120: 1 unresolved externals ...\Debug\Project.exe 1 1..  - <em>(solved by adding main function)</em></p>
  
  <p>Error 3 IntelliSense: member "one::data1" (declared at line 19) is inaccessible ...\Friends.cpp - <strong>(Exists even after cleaning and rebuilding project)</strong></p>
  
  <p>I thought it might be a problem with how I implemented it, so I did a copy-paste to the  code in the answer:</p>
  
  <pre><code>class one;
  
  class two
  {
   private:
      int data2;
   public:
      two()
      {
         data2 = 200;
      }
      // this goes fine, because the function is not yet defined. 
      int accessboth(one a);
  };
  
  class one
  {
  private:
      int data1;
  public:
      one()
      {
         data1 = 100;
      }
      friend int two::accessboth(one a);
  };
  
  // don't forget "inline" if the definition is in a header. 
  inline int two::accessboth(one a)
  {
      return (a.data1 + (*this).data2);
  }
  </code></pre>
  
  <p>but I got the same error in the same place: <strong>a.data1</strong> was <em>inaccessible</em></p>
  
  <p>I then searched and found more examples that suggest the same technique to solve the problem, but they all gave me the same <em>inaccessible</em> error in the same place...</p>
  
  <p>Is there something I'm missing? should the provided example (suggested solution from previous post) work?
  Something changed in the specification maybe?</p>
  
  <p>thank you for any help.
  D</p>
  
  <p>P.S
  I tried commenting on the previous post in order not to open a new question about this, but was unable to comment due to low reputation (I'm new here).</p>