friend class declaration question

A

Alfonso Morra

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?
 
V

Victor Bazarov

Alfonso said:
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
 
M

Mercator

Victor said:
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.
 
A

Alfonso Morra

Alfonso said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top