friend class declaration question

Discussion in 'C++' started by Alfonso Morra, Jul 18, 2005.

  1. 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?
     
    Alfonso Morra, Jul 18, 2005
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Jul 18, 2005
    #2
    1. Advertising

  3. Alfonso Morra

    Mercator Guest

    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.
     
    Mercator, Jul 18, 2005
    #3
  4. 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
     
    Alfonso Morra, Jul 18, 2005
    #4
  5. Alfonso Morra

    David Harmon Guest

    On Mon, 18 Jul 2005 15:06:23 +0000 (UTC) in comp.lang.c++, Alfonso Morra <> wrote,

    >public:
    > friend class A ;


    >private:
    > friend class A ;


    Makes no difference.
     
    David Harmon, Jul 18, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john smith
    Replies:
    1
    Views:
    1,946
    Victor Bazarov
    Aug 10, 2003
  2. Yu Lianqing
    Replies:
    1
    Views:
    666
    Leor Zolman
    Apr 4, 2004
  3. Ovidesvideo
    Replies:
    4
    Views:
    550
    Andrey Tarasevich
    Dec 10, 2004
  4. kelvSYC
    Replies:
    6
    Views:
    7,365
    Richard Herring
    May 17, 2005
  5. Peter
    Replies:
    2
    Views:
    310
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page