// Non-friend/non-member functions cannot access // private data of a class. #include // Modified Count class class Count { public: Count() { x = 0; } // constructor void print() const { cout << x << endl; } // output private: int x; // data member }; // Function tries to modify private data of Count, // but cannot because it is not a friend of Count. void cannotSetX( Count &c, int val ) { c.x = val; // ERROR: 'Count::x' is not accessible } int main() { Count counter; cannotSetX( counter, 3 ); // cannotSetX is not a friend return 0; }