Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > friendship and pImpl idiom

Reply
Thread Tools

friendship and pImpl idiom

 
 
jimmy
Guest
Posts: n/a
 
      02-08-2006
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

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-08-2006
* 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?
 
Reply With Quote
 
 
 
 
jimmy
Guest
Posts: n/a
 
      02-09-2006
But then Foo has access to X's private stuff. That's worse. I'll just
stick to what I have. -b

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-09-2006
* 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pimpl idiom without dynamic memory allocation Daniel Lidström C++ 15 10-31-2007 11:51 PM
pimpl idiom and singletons Noah Roberts C++ 4 05-25-2007 06:00 PM
Pimpl idiom and member function templates Peteris Krumins C++ 2 08-31-2005 04:58 PM
Is the Bridge Pattern the same as Herb Sutter's Pimpl Idiom? Debajit Adhikary C++ 2 07-15-2004 01:25 PM
Pimpl Idiom Icosahedron C++ 7 11-22-2003 11:34 PM



Advertisments