O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required