How to devise function pointer type from function name?

N

Nitin

Hi,

Can I devise function pointer type from function name by using
template programming?
e.g.
I have function:
exertn “C” void xmlFreeDoc(xmlDocPtr cur);
I want something like following:
typeof(xmlFreeDoc) functionpointer = xmlFreeDoc;
i.e value to type conversion
I want pass this type to Holder which will call this function in dtor.

Currently I am using following code to do the same task:
extern "C" {
typedef void (*funcPtr)(void*) ;
}
Holder said:
children, 1), xmlFree);

Issues with above code:
I need to add every type of function in the extern “C” block.

Thanks,
Nitin.
 
J

Juha Nieminen

Nitin said:
I have function:
exertn “C” void xmlFreeDoc(xmlDocPtr cur);
I want something like following:
typeof(xmlFreeDoc) functionpointer = xmlFreeDoc;

With the upcoming C++ standard you will be able to do it like this:

decltype(smlFreeDoc) functionpointer = xmlFreeDoc;

Or in this specific case, more easily:

auto functionpointer = xmlFreeDoc;

(decltype is still useful for some cases, where you need the type
itself, rather than just to create a variable.)
 

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,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top