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. Advertisements

  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. Advertisements

  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. Advertisements

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. E11
    Replies:
    1
    Views:
    5,665
    Thomas Weidenfeller
    Oct 12, 2005
  2. Alexander Stippler

    nested classes and friend declaration

    Alexander Stippler, Jul 2, 2003, in forum: C++
    Replies:
    1
    Views:
    461
    Victor Bazarov
    Jul 2, 2003
  3. john smith
    Replies:
    1
    Views:
    2,094
    Victor Bazarov
    Aug 10, 2003
  4. eddiew_AUS
    Replies:
    18
    Views:
    814
    Andrey Tarasevich
    Jan 27, 2004
  5. Yu Lianqing
    Replies:
    1
    Views:
    759
    Leor Zolman
    Apr 4, 2004
  6. Ovidesvideo
    Replies:
    4
    Views:
    741
    Andrey Tarasevich
    Dec 10, 2004
  7. kelvSYC
    Replies:
    6
    Views:
    7,930
    Richard Herring
    May 17, 2005
  8. Peter
    Replies:
    2
    Views:
    490
    Öö Tiib
    Jun 6, 2013
Loading...