🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Scott Meyers Mon, 23 Oct 1995 21:56
Defining Member Templates
#2288
Author: Scott Meyers
Date: Mon, 23 Oct 1995 21:56
34 lines
1504 bytes
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?  

Scott

[ 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. ]
Re: Defining Member Templates
#2291
Author: John H. Spicer
Date: Tue, 24 Oct 1995 03:01
45 lines
1914 bytes
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads