Например, этот класс. Есть ли способ, чтобы функция, не являющаяся членом, выполняла задачу функции друга?Как функция, не являющаяся членом, может выполнять функцию друга класса?
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;
}
Друзей по определению являются не являющимися членами ... –
идеи частного что non member non friend не может получить к нему доступ. – Dani