Given the following code:
class Screen;
class WindowMgr
{
WindowMgr& relocateScreen( int r, int c, Screen& s);
};
class Screen
{
friend WindowMgr& WindowMgr::relocateScreen( int r, int c, Screen& s);
int m_nR,
m_nC;
};
WindowMgr& WindowMgr::relocateScreen( int r, int c, Screen& s)
{
s.m_nR = r;
s.m_nC = c;
return *this;
}
Why Screendoesn't the class declare a member function WindowMgr::relocateScreenas a friend? Screendoes not want to use this private member function of another class, but simply wants this function to have access to its own private members.
Creating a public function relocateScreencan be a bad design if it is intended only for use in a class WindowMgr. Likewise, making a Screenfriend WindowMgrcan be a bad design if it is not designed to access private members WindowMgrin any other way.
Where am I wrong here? What is the right approach? Am I really fooling myself?