Friend function: Difference between revisions

Content deleted Content added
Removed broken link
m Use cases: consistently "method" (already three times in the intro and also category)
 
Line 10:
This may be accomplished in two similar ways:
*A function of global or [[namespace]] scope may be declared as friend of both classes.
*A member functionmethod of one class may be declared as friend of another one.
<syntaxhighlight lang="cpp">
// C++ implementation of friend functions.
Line 23:
public:
void show(Bar& x, Foo& y);
friend void show(Bar& x, Foo& y); // declaration of global function as friend
};
Line 30:
int b = 6;
public:
friend void show(Bar& x, Foo& y); // declaration of global function as friend
friend void Bar::show(Bar& x, Foo& y); // declaration of friend from other class
};
// Definition of a member functionmethod of Bar; this member is a friend of Foo
void Bar::show(Bar& x, Foo& y) {
cout << "Show via function member of Bar" << endl;