Friend Function
#include <bits/stdc++.h>
using namespace std;
class rect
{
int val;
public:
friend void printLength(rect);
// can be written in private also.
friend int main();
// we can also make main as a friend function.
rect()
{
val = 10;
}
};
void printLength(rect a)
{
cout << a.val;
}
int main()
{
rect a;
cout << a.val;
printLength(a);
}
Comments
Post a Comment