Re: Templates

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 12/10/04


Date: Fri, 10 Dec 2004 11:14:14 -0500

Mike Gleason Jr Couturier wrote:
> Is it possible to do a thing like that and
> invoke test::Function by passing a class
> name (un-quoted) ?
>
> class test
> {
> public:
> test(){};
> virtual ~test(){};
>
> template<class T> void Function(){[...]};
> };

You can safely drop the three semicolons out of four in this program
and definitely the "[...]". You will still have valid C++ code.
However, it would be nice if you added the code where you'd show how
you intended to call test::Function (what is known as a "driver").
I submit that this:

     class test
     {
     public:
         test() {}
         virtual ~test() {}

         template<class T> void Function() {}
     };

     int main()
     {
         test t;
         t.Function<double>();
     }

is probably what you need. Is it? It compiles fine with VC++ v7.1...

Victor



Relevant Pages

  • Re: Fastest way to retrieve bit position within a __int64 (VC++ 6)
    ... "Mike Gleason Jr Couturier" wrote in ... > I'm looking for a solution to avoid a loop for a function: ...
    (microsoft.public.vc.language)
  • Re: static const struct {...} myStruct[];
    ... "Mike Gleason Jr Couturier" wrote in ... > It is actually a member of a class: ... and it could be dangerous sitting under them as they fly ...
    (microsoft.public.vc.language)
  • Re: Templates
    ... I tried it before posting.. ... error C2275: 'CMyType': illegal use of this type as an expression ... > Mike Gleason Jr Couturier wrote: ...
    (microsoft.public.vc.language)
  • Re: /etc/resolv.conf
    ... >Mike Gleason Jr Couturier wrote: ... >> Do I have to reboot whenever I make changes ... but it's worth noting that many long-running daemons (e.g. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Templates
    ... Mike Gleason Jr Couturier wrote: ... > I don't mean to be rude... ... I never understood where top-posts ...
    (microsoft.public.vc.language)