Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/02/2014, 05:33
dehm
 
Fecha de Ingreso: septiembre-2010
Mensajes: 494
Antigüedad: 13 años, 7 meses
Puntos: 10
Respuesta: Punteros a plantillas de funciones...¿posible?

Bueno, pues al menos poder, parece que se puede....pero no sé cómo aplicarlo en mi caso.
Código C++:
Ver original
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. T maximo (T a, T b)
  6. {
  7.     if (a>b)
  8.     {
  9.         return a;
  10.     }
  11.     return b;
  12. }
  13.  
  14. template <typename TT>
  15. struct functor
  16. {
  17.     TT _a;
  18.     TT _b;
  19.     functor (TT a=0, TT b=0): _a(a),_b(b){}
  20.     TT operator()()
  21.     {
  22.         if (_a>_b)
  23.         {
  24.             return _a;
  25.         }
  26.         return _b;
  27.     }
  28. };
  29.  
  30. int main()
  31. {
  32.  
  33.     int(*maxint)(int a,int b)=&maximo;
  34.     float(*maxfloat)(float a, float b)=&maximo;
  35.  
  36.     cout<<maxint(800,80)<<endl;
  37.     cout<<maxfloat (6.75,6.755)<<endl;
  38.  
  39.     functor<int>i(4,5);
  40.     cout<<i()<<endl;
  41.  
  42.     functor<float>f(4.5,3.2);
  43.     cout<<f()<<endl;
  44.  
  45.     return 0;
  46. }

A ver si alguien me echa una mano...