Topic: Defining Member Templates


Author: "John H. Spicer" <jhs@edg.com>
Date: 1995/10/24
Raw View
Scott Meyers wrote:
>
> How can I define a member template outside the definition of the class?
> For example, consider this declaration for auto_ptr (from the latest
> DWP):
>
>     template<class X> class auto_ptr {
>     public:
>       template<class Y> auto_ptr(auto_ptr<Y>&);
>       ...
>     };
>   }
>
> If I want to implement this function inside the class template, that's
> easy,
>
>     template<class X> class auto_ptr {
>     public:
>       template<class Y> auto_ptr(auto_ptr<Y>&) { /* impl goes here */ }
>       ...
>     };
>   }
>
> but what if I want to put it outside the class definition?  Then what
> do I say?  The only thing I can think of is this:
>
>   template<class X>
>     template<class Y> auto_ptr(auto_ptr<Y>&) { /* impl goes here */ }
>
> Is this the right way to do it?
>

Almost.

template <class X>
 template <class Y> auto_ptr<X>::auto_ptr(auto_ptr<Y>&) { }

--
John Spicer
Edison Design Group
jhs@edg.com
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]