473,321 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

friend class declaration question

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
4 2878
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
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. ...
2
by: Christophe Barbe | last post by:
I am not clear about friend functions of a template class. GCC (3.3.2) wants me to add <> after the friend function names in the class declaration and VisualC++ doesn't like that. template...
1
by: Dmitry D | last post by:
Hi all, I'm having problems with declaring a template friend function. It seems like I've done everything as explained in C++ FAQ, but still, I'm getting the linker error (unresolved external...
5
by: Trevor Lango | last post by:
What is the appropriate syntax for placing a friend function that includes as one of it's parameters a pointer to the class object itself within the template class? I have the following: ...
6
by: Adam Parkin | last post by:
Hello, all I'm having a problem with friend functions in a templatized Queue class I'm writing using linked lists. The problem is that I can't get the friend function to be able to access private...
2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
9
by: Neelesh | last post by:
I was reading TC++PL (Chapter 11, section 11.5.1 "finding friends") where it is mentioned that What I observe is a bit different - it is fine that there is an error for Xform, but the reason...
9
by: Ivan Mascovich | last post by:
Previous posts (and compilers) confirm that class X { friend void Y() ; } ; does not match namespace
6
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.