468,241 Members | 1,592 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

friendship and pImpl idiom

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

Feb 8 '06 #1
3 2479
* 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?
Feb 8 '06 #2
But then Foo has access to X's private stuff. That's worse. I'll just
stick to what I have. -b

Feb 9 '06 #3
* 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?
Feb 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Icosahedron | last post: by
6 posts views Thread by Asfand Yar Qazi | last post: by
2 posts views Thread by Debajit Adhikary | last post: by
2 posts views Thread by Peteris Krumins | last post: by
9 posts views Thread by Edward Diener | last post: by
34 posts views Thread by Asfand Yar Qazi | last post: by
4 posts views Thread by Noah Roberts | last post: by
14 posts views Thread by Daniel Lidström | last post: by
2 posts views Thread by Graham Reitz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.