2008/2/7 personaje <[EMAIL PROTECTED]>:
> Hola programadores amigos...
>
>
>    tengo una clase así:
>
>  
> -------------8<-------------8<-------------8<-------------8<-------------8<-------------
>
>  class A
>  {
>  public:
>    typedef void(*TipoFuncion)();
>
>    void Registrar(TipoFuncion func){m_func = func;}
>    void Correr(){m_func();}
>  private:
>    TipoFuncion m_func;
>  };
>
>  class B
>  {
>  public:
>    void B(std::string Nombre):m_nombre(Nombre){}
>    void FuncionCopada(){std::cout<<m_nombre<<std::endl;}
>    void FuncionNoCopada(){std::cout<<"No hay nada que ver en
>  "<<m_nombre<<std::endl;}
>  private:
>    std::string m_nombre;
>  };
>
>
>  int main()
>  {
>    A a;
>    B b1("b1");
>    B b2("b2");
>
>    a.Registrar(B::FuncionCopada);
>    a.Correr();
>    a.Registrar(B::FuncionNoCopada);
>    a.Correr();
>  }
>
>  
> -------------8<-------------8<-------------8<-------------8<-------------8<-------------
>
>  Algo así, y la corrida debería dar:
>
>  b1
>  No hay nada que ver en b2
>
>  Este código me tira :
>
>  test.cpp: In function 'int main()':
>  test.cpp:32: error: invalid use of non-static member function 'void
>  B::FuncionCopada()'
>  test.cpp:34: error: invalid use of non-static member function 'void
>  B::FuncionNoCopada()'
>
>  Pero si las paso a estáticas, no tengo acceso a los miembros.
>
>  Cómo se puede lograr algo así? en particular tratando de no usar templates :)

Para este tipo de cosas lo mejor es utilizar Boost. ( www.boost.org )

Mira:
* Boost.Function ( http://www.boost.org/doc/html/function.html ) [
Member functions ]
* Boost.Bind ( http://www.boost.org/libs/bind/bind.html ) [ Using bind
with pointers to members ]

Un abrazo
Mat

_______________________________________________
Lista de correo Programacion.
[email protected]
http://listas.fi.uba.ar/mailman/listinfo/programacion

Responder a