title: Why can I not instantiate a class whose constructor is private in a friend class?
body: <p>I have two classes; <code>Salary</code> that is intended to hold information and calculations regarding the salary of an employee and <code>Employee</code> that has an object of type <code>class Salary</code> and some members like name and address of the employee...</p>
  
  <ul>
  <li><p>What I want to do is to prevent <code>class Salary</code> from being instantiated except by  <code>class Employee</code>. So I declared the constructors of <code>Salary</code> private and made <code>Employee</code> a friend of <code>Salary</code>. But I get errors:</p>
  
  <pre><code>class Employee;
  
  class Salary {
      public:
  
      private:
          Salary() : revenue_{}, cost_{} {}
          Salary(int x, int y) : revenue_{ x },
          cost_{ y } {
  
          }
          int revenue_, cost_;
          friend class Employee;
  };
  
  class Employee {
      public:
          std::string name_;
          Salary sal;
  };
  
  int main(){
  
      Employee emp{}; // "Salary::Salary()" is inaccessible
  }
  </code></pre></li>
  <li><p>The problem goes away if I forward declare <code>main</code>: </p>
  
  <pre><code>int main(int, char*[]);
  </code></pre>
  
  <p>And make <code>main</code> a friend of <code>class Salary</code> like so in Salary:</p>
  
  <pre><code>class Salary {
      //...
      friend int main(int argc, char* argv[]);
  };
  </code></pre></li>
  </ul>
  
  <p>Now the program compiles correctly!</p>
  
  <p>*** Another thing in main if I declare an object this way:</p>
  
  <pre><code>Employee emp; // ok
  Employee emp{}; // error?
  </code></pre>