473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2844
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Icosahedron | last post by:
I've been going through some old code trying to clean it up and rearchitect it based on more modern C++ idioms. In the old code I often used the Pimpl idiom on a class by class basis, creating...
6
by: Asfand Yar Qazi | last post by:
Hi, Now that GCC 3.4 has precompiled headers, I'm thinking I can stop using pimpls to speed up development time, as it may make life easier (declaring pimpls takes a long time...) What are...
2
by: Debajit Adhikary | last post by:
I'm still pretty new to design patterns... I was wondering, is there any difference between the Bridge Pattern and Herb Sutter's Pimpl Idiom? Both delegate responsibility to an implementation...
2
by: Peteris Krumins | last post by:
Hello! I was playing around pimpl idiom and discovered that there is a problem with it if a class member template function exists which has to access private data, since only the forward...
9
by: Edward Diener | last post by:
Because 'friend' is not recognized in MC++, using the pImpl idiom in MC++ classes seems nearly impossible. Normally a pImpl class is a 'friend' to the class for which it supplies the private...
34
by: Asfand Yar Qazi | last post by:
Hi, I'm creating a library where several classes are intertwined rather tightly. I'm thinking of making them all use pimpls, so that these circular dependancies can be avoided easily, and I'm...
4
by: Noah Roberts | last post by:
Some little tidbit I just ran into that might help some, especially novice programmers. If you are using the pimpl idiom, as you probably should be most of the time, then it is very...
14
by: Daniel Lidström | last post by:
Hello! I have just discovered a way to use the private implementation idiom (pimpl), without the overhead of dynamic memory allocation. For those of you who don't know what this is, Wikipedia...
2
by: Graham Reitz | last post by:
What are good strategies for selecting, either at run-time or compile time, various pimpl'ed implementations? While retaining the ability to switch implementations without recompiling. Boost...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.