Defining a Nested Class outside of the Enclosing Class

Inside TextQuery we declared QueryResult but did not define it. As with member functions, nested classes must be declared inside the class but can be defined either inside or outside the class.

When we define a nested class outside its enclosing class, we must qualify the name of the nested class by the name of its enclosing class:

// we're defining the QueryResult class that is a member of class TextQueryclass TextQuery::QueryResult {    // in class scope, we don't have to qualify the name of the QueryResult parameters    friend std::ostream&           print(std::ostream&, const QueryResult&);public:    // no need to define QueryResult::line_no; a nested class can use a member    // of its ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.