Help on using template

I wonder if any one can help on this. I am trying to do a simple template class like this:

template<typename T1,typename T2>
class myClass
{
T1 fun(T2 arg);
}

Normally I can create an object of the class by
myClass<double,double> a;

I want to know if there is any way that I can do the same by this?

myClass<double(double)> a;

Many thanks in advance!

Jenny






double(x) calls the constructor doesn't it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
template< typename FUNCTION > class my_class
{
     public:
         explicit my_class( FUNCTION f ) : fun(f) {}

         FUNCTION* fun ;

        // ...
};

double my_function( double d ) { return d ; }

my_class< double(double) > a( my_function ) ;



#include <functional> // C++11

template< typename R, typename A > class another_class
{
     public:
         another_class( std::function< R(A) > f ) : fun(f) {}

         std::function< R(A) > fun ;

        // ...
};

another_class< double, double > b( my_function ) ;
Topic archived. No new replies allowed.