From 8413936907371126402
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,f0db50d81b8463ea
X-Google-Attributes: gidf78e5,public
From: Pete Becker <petebecker@acm.org>
Subject: Re: Member functions of class templates
Date: 1997/12/15
Message-ID: <3493F4F7.97160081@acm.org>#1/1
X-Deja-AN: 298455194
References: <199712111833.LAA15148@ncar.ucar.EDU> <34918c26.2428088350@nntp.americasttv.com>
X-Original-Date: Sun, 14 Dec 1997 10:02:15 -0500
Organization: MediaOne -=- Northeast Region
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNJWE50y4NqrwXLNJAQHjBgIAlXNf8H49m9K1dhEXKS5vK7Rf2SI9PO6T MDRCnBSgk9jqdzW6KvNuq1oDLlgl+2rPSGYJGcxOfUqTEiF+xbZluA== =WL1A
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


Stanley Friesen wrote:
> 
> On 11 Dec 1997 18:21:56 PST, Luddy Harrison <luddy@concmp.com> wrote:
> 
> >
> >Could someone familiar with the intent behind this wording give me an
> >example of this rule at work?  It seems to imply that if I write
> >
> >   template <class S> class T {
> >      public:
> >        int f(S*);
> >        int g();
> >   };
> >
> >that f is (implicitly) a function template, which I would interpret to
> >mean that more than one f can be instantiated from this declaration,
> >according to the argument types presented to f at a call.
> 
> Yes.

Well, not really. There is no template function f(S*) dangling out
there. You can only name it in the context of some class T<S>, which is
what determines the type of S:

template <class S> class T {
   public:
     int f(S);
};
int main()
{
T<int> ti;
ti.f(3);	// calls T<int>::f(int)
ti.f(3.0);	// calls T<int>::f(int)
}

The purpose of this rule is simplify the description of how member
functions of template classes work. There is, however, a mechanism for
creating member function templates:

template <class S> class T {
   public:
     template<class U> int f(U);
};

Now the argument to f() determines what gets instantiated:

int main()
{
T<int> ti;
ti.f(3);	// calls T<int>::f(int)
ti.f(3.0);	// calls T<int>::f(double)
}
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



