You are most of the way there, you just need to ensure that you declare all of your classes and functions before you require that declaration.
The first instruction point says to define the Window_mgr
class declaring Window_mgr::clear
. In order to use Screen
, that class must also be declared before Window_mgr
. This looks like:
class Screen; //forward-declare Screen so that Window_mgr knows it exists
class Window_mgr {
public:
//requires forward declaration of Screen, like the above
using ScreenIndex = std::vector<Screen>::size_type;
void clear (ScreenIndex); //declare, but don't define, clear
};
The second point says to define Screen
and include a friend declaration for Window_mgr::clear
. Because that member function has already been declared above, this is valid:
class Screen
{
public:
using ScreenIndex = std::vector<Screen>::size_type;
//remember to friend with the same arguments
friend void Window_mgr::clear(ScreenIndex);
//...
};
The final point tells you to now define Window_mgr::clear
. We have already declared in in the first point, so we just need to do this:
void Window_mgr::clear(ScreenIndex i)
{
//...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…