Content deleted Content added
→Use cases: Fixed typos and mentioned that the code is in C++. |
m →Use cases: consistently "method" (already three times in the intro and also category) |
||
(One intermediate revision by one other user not shown) | |||
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
<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
void Bar::show(Bar& x, Foo& y) {
cout << "Show via function member of Bar" << endl;
Line 63:
==External links==
*[http://www.codersource.net/c/ctutorials/ctutorialfriend.aspx C++ friend function tutorial] at CoderSource.net
[[Category:Method (computer programming)]]
|