... return this->isEmpty();
24      }
25
26      // printStack calls the List function print
27      void printStack() const {
28         this->print();
29      } 
30   };
31
32   #endif

19.4.3 Dependent Names in Class Templates

The explicit use of this on lines 23 and 28 is required so the compiler can properly resolve identifiers in template definitions. A dependent name is an identifier that depends on a template parameter. For example, the call to removeFromFront (line 18) depends on the argument data which has a type that’s dependent on the template parameter STACKTYPE. Resolution of dependent names occurs when the template is instantiated.

In contrast, the identifier for a function that takes no arguments like isEmpty or print in the List superclass is a non-dependent ...

Get C++ How to Program, 10/e 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.