Skip to content

Commit

Permalink
Merge pull request #29 from Kishun21/patch-3
Browse files Browse the repository at this point in the history
Create What is friend function in C++?
  • Loading branch information
narayancseian authored Oct 19, 2021
2 parents 4c31157 + fa360cf commit 6a75672
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions What is friend function in C++?
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Circle{
double radius;

public:
friend void printradius( Circle c );
};
void printradius(Circle c ) {
/* Because printradius() is a friend of Circle, it can
directly access any member of this class */
cout << "Radius of circle: " << c.width;
}

int main() {
Circle c;

// Use friend function to print the radius.
printradius( c);

return 0;
}

0 comments on commit 6a75672

Please sign in to comment.