Topic: template member functions


Author: "Philippe A. Bouchard" <philippeb@videotron.ca>
Date: 24 May 2002 23:08:50 GMT
Raw View
"Russell Smiley" <smiley@nortelnetworks.com> wrote in message
news:3CDFCE8B.AD59234@americasm01.nt.com...
>
>   template<class T_float>
>   template<>
>   long int Test<T_float>::member<long int> () {
>     cout << "long int member" << endl;
>   };

You cannot partly specialize functions because of the paradigm implied with
overloads.




      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]






Author: "Russell Smiley"<smiley@nortelnetworks.com>
Date: 13 May 2002 18:24:13 GMT
Raw View
Would somebody mind explaining why the following doesn't work?

  template<class T_float>
  class Test
  {
  public:
    Test () {};

    template<class T_int>
    T_int member ();
  };

  template<class T_float>
  template<>
  long int Test<T_float>::member<long int> () {
    cout << "long int member" << endl;
  };

  int main (void)
  {
    Test<double> p;

    p.member<long int>();
  }


I already have some work arounds to achieve the same syntactic
appearance; I'm just looking for an explanation of why this natural
progression of template specialisation (from function, to class, to
member function) doesn't work.

Thanks for your help.

Russell.

--
smiley@nortelnetworks.com, Ph. +1 613 765 7055, Fax +1 613 765 2592



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]






Author: Hyman Rosen <hyrosen@mail.com>
Date: 14 May 2002 00:07:21 GMT
Raw View
Russell Smiley wrote:
> Would somebody mind explaining why the following doesn't work?

The problem is that once you utter 'template<>' you are in the
realm of explicit specialization, which comes with a whole set
of burdensome rules and restrictions (14.7.3) and is so strange
that it inspired a limerick in the standard (14.7.3/7).


      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]






Author: babucher@mtu.edu (Brian A. Bucher)
Date: 31 Oct 1994 23:17:31 GMT
Raw View
Rohan LENARD (rjl@f111.iassf.easams.com.au) wrote:
: Hi folks,
:
: Could someone please tell me whether the following is the correct syntax
: for the code definition for the template member function declared below -
:
: class Foo {
: public:
:   template <class T> void DoSomething(T& a);
: };
:
: template <class T> void Foo::DoSomething<T>(T& a)
: {
:   cout << a;
: }
:
: Regards,

OK, let me see if i can get this right...as I am learning templates right now.

template <class T>
class Foo{
 void DoSomething(T&);
}
template <class T>
void Foo<T>::DoSomething(T &blah)
{ cout << blah;
}


ALL: any corrections you feel need be brought up?

Rohan-
If I understand you correctly, that is how you would write it.
later
--
-----------------------------------------------------------------
Brian Bucher - Computer Consultant, Division of Chemical Sciences




Author: rjl@f111.iassf.easams.com.au (Rohan LENARD)
Date: 27 Oct 1994 14:39:11 +1000
Raw View
Hi folks,

Could someone please tell me whether the following is the correct syntax
for the code definition for the template member function declared below -

class Foo {
public:
  template <class T> void DoSomething(T& a);
};

template <class T> void Foo::DoSomething<T>(T& a)
{
  cout << a;
}

Regards,
 Rohan
--
----------------------------------------------------------------------------
rjl@iassf.easams.com.au | All quotes can be attributed to my automated quote
Rohan Lenard            | writing tool.  Yours for just $19.95; and if you
+61-2-367-4555          | call now you'll get a free set of steak knives ...