c++ - How can I create a variable with the same type as a given function? -


i have c++ function like

int f( const std::string &s, double d ); 

now i'd create variable holds pointer f. variable should have correct type (int (*)( const std::string &, double ) - don't want write out type explicitely. i'd deduce f don't repeat type signature. eventually, i'd able write along lines of:

typeof<f>::result x = f; 

to achieve this, tried this:

// never implemented, used deduce return type can typedef'ed template <typename t> t deducetype( t fn );   template <typename t> struct typeof {     typedef t result; };  // ... typeof<deducetype(f)>::result x = f; 

my hope maybe return type of function (deducetype, in case) used template argument alas - seems can't that.

does know how this? i'm looking c++03 solution.

c++0x added decltype want (if understood correctly).

another option might boost::typeof intended provide same functionality until decltype supported in compilers.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -