[vtk-developers] Members of smartpointers as observers

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Sat Oct 9 10:36:31 EDT 2010


How about

 renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent,
  style2.GetPointer(), &MyInteractorStyle::KeypressCallbackFunction)

Utkarsh

On Sat, Oct 9, 2010 at 9:55 AM, David Doria <daviddoria at gmail.com> wrote:
> I made an example of the new class member observer functionality:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/ObserverMemberFunction
>
> This worked fine:
>  MyInteractorStyle* style = MyInteractorStyle::New();
>  renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent,
> style, &MyInteractorStyle::KeypressCallbackFunction);
>
> While this produced errors:
>  vtkSmartPointer<MyInteractorStyle> style2 =
>    vtkSmartPointer<MyInteractorStyle>::New();
>  renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent,
> style2, &MyInteractorStyle::KeypressCallbackFunction);
>
> Is there a way to set a member of a smart pointer to a class as the callback?
>
> Also, if someone wants to add the code for properly handling the
> dangling pointers that would be great.
>
> David
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>



More information about the vtk-developers mailing list