#include <iostream>
using namespace std;
class Count
{
  friend void setX(Count &,int);// friend declaration
  public:
    Count(): x( 0 ) // initialize x to 0
    {  } 
    void print() const{
      cout << x << endl;
    } 
  private:
    int x;
}; 

void setX( Count &c, int val ){                                                         
  c.x = val;//allowed because setX is a friend of Count
}
main()
{
  Count counter; // create Count object
  cout << "counter.x after instantiation: ";
  counter.print();
  
  //cout<<"Size of counter = "<<sizeof(counter)<<endl;
  setX( counter, 8 ); // set x using a friend function
  cout << "counter.x after call to \nsetX friend function: ";
  counter.print();
  system("pause");
} // end main
