I have a C ++ function like
int f( const std::string &s, double d );
Now I would like to create a variable that contains a pointer to f . This variable must have the correct type ( int (*)( const std::string &, double ) - but I do not want to explicitly write out this type. I would like to draw a conclusion from f so that I do not repeat the type signature. In the end, I "I like to write something line by line:
TypeOf<f>::Result x = f;
To achieve this, I tried to do something like this:
// Never implemented, only used to deduce the return type into something which can be 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 was that perhaps the return type of the function ( deduceType , in this case) could be used as an argument to the template, but, alas, it looks like you can't do this.
Does anyone know how to do this? I am looking for a C ++ 03 solution.
c ++ templates
Frerich raabe
source share