[vtkusers] vtkRenderWindow::SetExitMethod to close vtkRenderWindow

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Fri Oct 26 12:27:33 EDT 2001


hi,

>>>>> "AU" == Anwar Upal <upal at me.queensu.ca> writes:

    AU> I have defined a newExitMethod in the class that also includes
    AU> the function which calls the vtkRenderWindowInteractor. The
    AU> newExitMethod structure looks like:

    AU> 	void classname::newExitMethod(void *arg) { }

    AU> And the code that calls vtkRenderWindowInteractor is as shown
    AU> below:

    AU> 	vtkRenderWindowInteractor *iren =
    AU> vtkRenderWindowInteractor::New();
    iren-> SetExitMethod (newExitMethod,NULL);

Looks like your code is wrong.  Read Stroustrup or any good c++ book
and look at the section on pointers to functions and pointers to
member functions.  The expected arguments are a pointer to a function
and a void *. In your case, the first argument is wrong.

    AU> vtkRenderWindowInteractor::SetExitMethod(void (*)(void *),
    AU> void *)"

 (1) It expects a pointer to a function.  A member function is NOT the
 same as a function.  

 (2) If you want to use a member function as the Exit callback then
 you have to make it static.  Why? Because there isnt any instance of
 your class that the vtkRenderWindowInteractor can use.  So how can it
 make a call to the function?

    AU> How can I fix this error? And what should my custom method
    AU> newExitMethod do to give me back control (and just close the
    AU> vtk window instead of terminating my application and user
    AU> interface).

Honestly, I think it is a good idea for you to review pointers to
functions and member functions.  The c++ syntax for this is also
pretty funny so its rather easy to get mixed up and even forget
things.

prabhu



More information about the vtkusers mailing list