473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Template specialization of pointers with function pointers

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.
Jul 19 '05 #1
1 2816
co*******@hotmail.com (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.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
12
by: Surya Kiran | last post by:
Hi all, I've written a function template. say template <class T> fn (T var) { ... } Is there any way, from within the function, can we check what type of argument we've passed on to the...
2
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing member functions and came across a simple problem...
6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
2
by: Thomas Kowalski | last post by:
Hi, I would like to write a template class Polygon<VertexTypthere vertex typ can be eigther a pointer or a value typ. It has an attribute: std::vector<VertexTypvertices; And a methode:...
8
by: mattias.nissler | last post by:
Hi! Here is a problem I ran into at work. The following example doesn't compile on gcc-4.1: struct cons_end {}; template<typename U,typename Vstruct cons { U elem; V tail;
9
by: stephen.diverdi | last post by:
Can anyone lend a hand on getting this particular template specialization working? I've been trying to compile with g++ 4.1 and VS 2005. ...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
6
by: johnbrown105 | last post by:
Is it possible to force the compiler to use a generic template rather than a matching specialisation? Consider the following: ////////////////////////////////////////// template.cpp starts...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.