friendship and pImpl idiom

Discussion in 'C++' started by jimmy, Feb 8, 2006.

  1. jimmy

    jimmy Guest

    Hi,

    I had a class Foo that grants friendship to a class FooFriend. I then
    wanted to use the pImpl idiom to FooFriend. So I have something like
    this,

    class FooFriend
    {
    private:
    class FooFriendImpl;
    FooFriendImpl *pImpl;
    }

    class FooFriend;
    class FooFriend::FooFriendImpl;
    class Foo
    {
    friend class FooFriend;
    friend class FooFriend::FooFriendImpl; // error here
    }

    I would like to keep class FooFriend::FooFriendImpl but not sure if
    this is possible. Any suggestions? I would think many people have come
    accross this problem.

    -Jimmy
     
    jimmy, Feb 8, 2006
    #1
    1. Advertising

  2. * jimmy:
    > Hi,
    >
    > I had a class Foo that grants friendship to a class FooFriend. I then
    > wanted to use the pImpl idiom to FooFriend. So I have something like
    > this,
    >
    > class FooFriend
    > {
    > private:
    > class FooFriendImpl;
    > FooFriendImpl *pImpl;
    > }


    Missing semicolon. Hence: is this the actual code? Very little can be
    said about errors in the actual code based on hypothetical example.


    > class FooFriend;
    > class FooFriend::FooFriendImpl;
    > class Foo
    > {
    > friend class FooFriend;
    > friend class FooFriend::FooFriendImpl; // error here


    You're accessing a private (inaccessible) feature of FooFriend.

    > }


    Missing semicolon.


    > I would like to keep class FooFriend::FooFriendImpl but not sure if
    > this is possible. Any suggestions? I would think many people have come
    > accross this problem.


    class Foo;

    class X
    {
    friend class Foo;
    private:
    class Y;
    };

    class Foo
    {
    friend class X;
    friend class X::Y;
    };


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Feb 8, 2006
    #2
    1. Advertising

  3. jimmy

    jimmy Guest

    But then Foo has access to X's private stuff. That's worse. I'll just
    stick to what I have. -b
     
    jimmy, Feb 9, 2006
    #3
  4. * jimmy:
    > But then Foo has access to X's private stuff. That's worse. I'll just
    > stick to what I have. -b


    Please quote what you're replying to.

    That said, just make the declaration of Y public instead of private; I
    presumed there was some reason you wanted it private, and that implied
    friendship granted to Foo.

    The whole point of PIMPL is that nobody has access to the innards of Y,
    except the implementation file, regardless of whether the class name is
    accessible elsewhere.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Feb 9, 2006
    #4
    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. Icosahedron

    Pimpl Idiom

    Icosahedron, Nov 20, 2003, in forum: C++
    Replies:
    7
    Views:
    726
    Icosahedron
    Nov 22, 2003
  2. Debajit  Adhikary
    Replies:
    2
    Views:
    2,053
    Christopher Benson-Manica
    Jul 15, 2004
  3. Peteris Krumins
    Replies:
    2
    Views:
    507
    Peteris Krumins
    Aug 31, 2005
  4. Noah Roberts

    pimpl idiom and singletons

    Noah Roberts, May 24, 2007, in forum: C++
    Replies:
    4
    Views:
    446
    Noah Roberts
    May 25, 2007
  5. Daniel Lidström
    Replies:
    15
    Views:
    647
    Brendon Costa
    Oct 31, 2007
Loading...

Share This Page