比如这个班。有没有可能让非会员功能执行好友功能的任务?一个非成员函数如何实现一个类的朋友函数呢?
class Accumulator
{
private:
int m_nValue;
public:
Accumulator() { m_nValue = 0; }
void Add(int nValue) { m_nValue += nValue; }
// Make the Reset() function a friend of this class
friend void Reset(Accumulator &cAccumulator);
};
// Reset() is now a friend of the Accumulator class
void Reset(Accumulator &cAccumulator)
{
// And can access the private data of Accumulator objects
cAccumulator.m_nValue = 0;
}
朋友被定义为非会员... – 2014-09-21 03:25:38
私人的想法是,非会员非朋友无法访问它。 – Dani 2014-09-21 03:33:13