I am following C++ Primer, and currently trying to understand class. Here is this example inside the book:
class Window_mgr //Window_mgr class definition
{
public:
using ScreenIndex = std::vector<Screen>::size_type;
void clear(ScreenIndex);
private:
std::vector<Screen> screens {Screen(24,80,' ')};
};
class Screen //Screen class definition
{
public:
friend void Window_mgr::clear(ScreenIndex);
using pos = std::string::size_type;
/* lots of codes thereafter (from the book) */
};
when I try to 'Build' (on CodeBlocks 20.03 on Win 10), I get the following errors:
I:\C++ Projects and source files\ScribblingRough.cpp|13|error: 'Screen' was not declared in this scope|
I:\C++ Projects and source files\ScribblingRough.cpp|13|note: suggested alternative: '_freea'|
I:\C++ Projects and source files\ScribblingRough.cpp|13|error: template argument 1 is invalid|
I:\C++ Projects and source files\ScribblingRough.cpp|13|error: template argument 2 is invalid|
I:\C++ Projects and source files\ScribblingRough.cpp|15|error: 'ScreenIndex' has not been declared|
I:\C++ Projects and source files\ScribblingRough.cpp|18|error: 'Screen' was not declared in this scope|
I:\C++ Projects and source files\ScribblingRough.cpp|18|note: suggested alternative: '_freea'|
I:\C++ Projects and source files\ScribblingRough.cpp|18|error: template argument 1 is invalid|
I:\C++ Projects and source files\ScribblingRough.cpp|18|error: template argument 2 is invalid|
I:\C++ Projects and source files\ScribblingRough.cpp|18|error: 'Screen' was not declared in this scope|
I:\C++ Projects and source files\ScribblingRough.cpp|18|note: suggested alternative: 'screens'|
I:\C++ Projects and source files\ScribblingRough.cpp|18|error: cannot convert '<brace-enclosed initializer list>' to 'int' in initialization|
I:\C++ Projects and source files\ScribblingRough.cpp|24|error: 'ScreenIndex' has not been declared|
I:\C++ Projects and source files\ScribblingRough.cpp|93|error: variable or field 'clear' declared void|
I:\C++ Projects and source files\ScribblingRough.cpp|93|error: 'ScreenIndex' was not declared in this scope|
I:\C++ Projects and source files\ScribblingRough.cpp|93|note: suggested alternative: 'Screen'|
I have followed the instructions from the book: First defining the Window_mgr class (which declares, but not define clear) Second - define Screen class including a friend declaration for clear Finally define clear.
Please help me understand my errors of understanding. Thanks.