Topic: friend function
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/04/15 Raw View
Michael Nissim wrote:
>
> Can a friend function use member functions, or does it only have access to
> private member variables?
Yes, it can use member functions.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Eric Tetz" <etetz@www.anything.com>
Date: 1999/04/15 Raw View
Michael Nissim wrote
> Can a friend function use member functions, or does it only have access
to
> private member variables?
A friend can access any private or protected part. Questions of this
nature are easily answered by experimentation. If I were you, the first
thing I would have done it try it. I whipped you up an example, because it
was too fun not too :)
#include <iostream.h>
class Girl; // forward declaration
class Boy
{
private:
// only boys know this secret
int NumFamilyJewels ()
{
return 2;
}
// well, only boys and their girlfriends...
friend Girl;
};
class Girl
{
public:
int Grope (Boy & boy)
{
// see? a Girl can access a Boy's private parts...
return boy.NumFamilyJewels();
}
};
int main()
{
Boy fred;
Girl sue;
cout << "Fred has " << sue.Grope (fred) << " family jewels" << endl;
return 0;
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: bernd.teegen@t-online.de (=?iso-8859-1?Q?Bj=F6rn?= Teegen)
Date: 1999/04/11 Raw View
Hallo Alex!
> Can a friend function use member functions, or does it only have access=
to
> private member variables?
A function that is a friend to a class A is allowed to use all of A's mem=
bers,
also its member functions.
Bj=F6rn
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Michael Nissim" <arnessim@inter.net.il>
Date: 1999/04/10 Raw View
Can a friend function use member functions, or does it only have access to
private member variables?
Thanks, Alex
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Barry Margolin <barmar@bbnplanet.com>
Date: 1999/04/11 Raw View
In article <7eihuo$16b$2@news2.inter.net.il>,
Michael Nissim <arnessim@inter.net.il> wrote:
>Can a friend function use member functions, or does it only have access to
>private member variables?
A friend function has all the same access as a member function, so it can
access all private members.
--
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: awbone@be.the.spam.mindspring.com (Ash)
Date: 1999/04/11 Raw View
On 10 Apr 99 04:36:11 GMT, "Michael Nissim" <arnessim@inter.net.il>
wrote:
>Can a friend function use member functions, or does it only have access to
>private member variables?
A friend can use any member of the class, functions included.
Of course, you must provide an object of that class to call/access
non-static members.
ashley
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]