How to devise function pointer type from function name?

Discussion in 'C++' started by Nitin, Sep 12, 2008.

  1. Nitin

    Nitin Guest

    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.
     
    Nitin, Sep 12, 2008
    #1
    1. Advertising

  2. 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.)
     
    Juha Nieminen, Sep 12, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?Q?Fran=E7ois?= Pinard

    How to devise run-time pluggable classes? (MRO problem)

    =?iso-8859-1?Q?Fran=E7ois?= Pinard, Aug 20, 2005, in forum: Python
    Replies:
    0
    Views:
    356
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Aug 20, 2005
  2. Sergei Gnezdov

    type* name vs. type *name

    Sergei Gnezdov, Mar 29, 2005, in forum: C Programming
    Replies:
    5
    Views:
    301
    Gordon Burditt
    Mar 29, 2005
  3. lovecreatesbeauty

    Why (type*)pointer isn't equal to *(type**)pointer?

    lovecreatesbeauty, Jan 14, 2006, in forum: C Programming
    Replies:
    10
    Views:
    513
    Peter Shaggy Haywood
    Jan 17, 2006
  4. Diego Martins
    Replies:
    5
    Views:
    503
    Diego Martins
    Sep 5, 2006
  5. saurabh purnaye

    issue with the devise

    saurabh purnaye, Sep 7, 2010, in forum: Ruby
    Replies:
    0
    Views:
    120
    saurabh purnaye
    Sep 7, 2010
Loading...

Share This Page