Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Template specialization of pointers with function pointers

Reply
Thread Tools

Template specialization of pointers with function pointers

 
 
Phil
Guest
Posts: n/a
 
      09-16-2003
Ok, I have a template function for any pointer to type T:

template <typename T>
void func(T* p)
{
DoSomethingGeneric(p);
}

Can I specialize this template for pointers to functions (or pointers
to member functions, or pointers to anything)? I would like to do
something like this:

typedef void (*FUNCPTR)();

template <>
void func(FUNCPTR p)
{
DoSomethingSpecialWithFuncPtr(p);
}

but my compiler (Visual C++ 6) won't let me. I know VC6 is lacking in
support for templates, but I'd like to know if this is even legal
anyway. Thanks.
 
Reply With Quote
 
 
 
 
llewelly
Guest
Posts: n/a
 
      09-16-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Phil) writes:

> Ok, I have a template function for any pointer to type T:
>
> template <typename T>
> void func(T* p)
> {
> DoSomethingGeneric(p);
> }
>
> Can I specialize this template for pointers to functions (or pointers
> to member functions, or pointers to anything)? I would like to do
> something like this:
>
> typedef void (*FUNCPTR)();
>
> template <>
> void func(FUNCPTR p)
> {
> DoSomethingSpecialWithFuncPtr(p);
> }


Yes. This compiles as-is with most modern compilers,

>
> but my compiler (Visual C++ 6) won't let me.


It's time you got out of the pleistocene and got into the
holocene. You can get a better compiler from www.mingw.org,
www.bloodshed.net, and many other places. (You can even get one
from M$, provided you pay enough.)

> I know VC6 is lacking in
> support for templates, but I'd like to know if this is even legal
> anyway.


It's well-formed.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Full specialization of a member function template of a class template Dave C++ 4 06-04-2010 12:15 PM
specialization of a template function in a template class?!?!? pookiebearbottom@yahoo.com C++ 2 08-07-2006 01:08 PM
template specialization overriding non-specialization? Joseph Turian C++ 2 04-16-2006 02:46 PM
Specialization of member function template in template class? Joseph Turian C++ 4 03-20-2006 10:07 AM
Member template function specialization in a template class Ruben Campos C++ 3 02-15-2005 10:40 AM



Advertisments