General discussion


Declare member functions as friends

By Mark W. Kaelin Editor ·
Declare a member function as a friend of another class:

The June 16, C++ TechMail discusses the declaration of member functions as friends. Have you used this function in your applications? Tell us how you used it and why.

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

confusing example

by yukunix In reply to Declare member functions ...

I think author made a confusing code example. In first example, class B is a frend class of class A so that B has access to all member of A. But in next example, the member function f() of class A is declared as a friend function of class B, so A::f() has access to all member of class B.
The above is my understanding. Is that wrong? Anyway, I am confused.

Collapse -

re: confusing example

by Plenty In reply to confusing example

Actually, from my understanding what it means is that A::f() only as access to B::f() and whatever B makes available within that function, and not all of it's members.

The first example states B's entire class is a friend to A, thereby making allof A's members easily accessible to B. By specifying individual functions to be friends, you are allowing access by least privileged, which is best for security.


Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums