So, just how private is private, Private?
In C++, to what extent are the private parts of a class really truly private?
Quick — assuming that the Twice functions are defined in another translation unit that is included in the link, should the following C++ program compile and run correctly? If no, why not? If yes, what is the output?
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
At the heart of the solution lies this question: In C++, to what extent are the private parts of a class, such as Example 1's Twice, really truly private? In this column, I'll show how private names are definitely not accessible from outside nonfriend code, and yet they can and do leak out of a class in small ways — some of which are well-known, others of which aren't, and a few of which can even be done as a calculated, deliberate act.
posted on 2004-07-23 17:43 LeighSword 阅读(340) 评论(1) 编辑 收藏 举报