I was watching one of bucky's tutorials about friend functions and this was the code he used in his example:
#include <iostream>
using namespace std;
class StankFist
{
public:
StankFist(){stinkyVar=0;}
private:
int stinkyVar;
friend void stinkysFriend(StankFist &sfo); //My question is about this
};
void stinkysFriend(StankFist &sfo)
{
sfo.stinkyVar=99;
cout << sfo.stinkyVar << endl;
}
int main ()
{
StankFist bob;
stinkysFriend(bob);
}
I don't remember being taught the reason why you have to pass by reference can somebody point me to a place to read more about this or explain to me why it is done like this?