Template specialization of pointers with function pointers

P

Phil

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.
 
L

llewelly

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top