Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to devise function pointer type from function name?

Reply
Thread Tools

How to devise function pointer type from function name?

 
 
Nitin
Guest
Posts: n/a
 
      09-12-2008
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<xmlChar, funcPtr, false> val(xmlNodeListGetString(doc, cur_node-
>children, 1), xmlFree);


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

Thanks,
Nitin.
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      09-12-2008
Nitin wrote:
> 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.)
 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
issue with the devise saurabh purnaye Ruby 0 09-07-2010 02:11 PM
No audio devise is installed Fred Seaver Computer Support 3 03-16-2009 05:54 PM
How to devise run-time pluggable classes? (MRO problem) =?iso-8859-1?Q?Fran=E7ois?= Pinard Python 0 08-20-2005 06:35 PM
how to capture devise settings & drivers WCH Computer Support 1 09-28-2003 09:02 PM



Advertisments