By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

friend class declaration question

P: n/a
Is there a difference between these two:

Decl 1
=============
class A {} ;

class B {
public:
friend class A ;
......
private:
......
};
Decl 2
=============
class A {} ;

class B {
public:
......
private:
friend class A ;
};
Before you ask, I've had a look at parashift and a few other sites, but
this question is not explicitly addressed AFAIK - however, most (all?)
of the code have the friend declaration under the public decl. Is there
a standard/ what(if any) are the implications of either one of the two?

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Alfonso Morra wrote:
Is there a difference between these two:

Decl 1
=============
class A {} ;

class B {
public:
friend class A ;
......
private:
......
};
Decl 2
=============
class A {} ;

class B {
public:
......
private:
friend class A ;
};
Before you ask, I've had a look at parashift and a few other sites, but
this question is not explicitly addressed AFAIK - however, most (all?)
of the code have the friend declaration under the public decl. Is there
a standard/ what(if any) are the implications of either one of the two?


None whatsoever. Friendship is not exposed, nor can it be transferred.
Hence there is no difference where (in what access section) the friend
declaration appears.

V
Jul 23 '05 #2

P: n/a
Victor Bazarov wrote:
None whatsoever. Friendship is not exposed, nor can it be transferred.
Hence there is no difference where (in what access section) the friend
declaration appears.


Right. Friendship also is an implementation detail of a class. It's
therfore appropriate (but not mandatory) to put it in the private
section.

Jul 23 '05 #3

P: n/a


Alfonso Morra wrote:
Is there a difference between these two:

Decl 1
=============
class A {} ;

class B {
public:
friend class A ;
......
private:
......
};
Decl 2
=============
class A {} ;

class B {
public:
......
private:
friend class A ;
};
Before you ask, I've had a look at parashift and a few other sites, but
this question is not explicitly addressed AFAIK - however, most (all?)
of the code have the friend declaration under the public decl. Is there
a standard/ what(if any) are the implications of either one of the two?


thanks guys

Jul 23 '05 #4

P: n/a
On Mon, 18 Jul 2005 15:06:23 +0000 (UTC) in comp.lang.c++, Alfonso Morra <sw***********@the-ring.com> wrote,
public:
friend class A ; private:
friend class A ;


Makes no difference.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.