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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.