10.12. Member Templates

Global scope is not mandatory for template definitions. An alternative nesting technique is member templates. Here are the formats.

class Class_name {             // enclosing nontemplate class 
   . . .
   template <class TYPE1, class TYPE2, class TYPEN>
					Type function_name(signature);
   . . .
};

template <class TYPE>
class Class_name {             // enclosing template class
   . . .
   template <class TYPE1, class TYPE2, class TYPEN>
					Type function_name(signature);
   . . .
};

Member templates are nested template functions within nontemplate classes or template classes. Member templates improve encapsulation and behave just like normal template functions, except their scope is local to the enclosing class. Within a template class, member templates are handy ...

Get Navigating C++ and Object-Oriented Design 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.