[vtk-developers] pointer to a member method

William A. Hoffman billlist at nycap.rr.com
Fri Jun 4 10:02:55 EDT 2004


Calling a member function by pointer is tricky because the function is not
enough.  To be called a member function must also have a "this" pointer.
If you made it a static member function it should work.   

-Bill


At 07:09 AM 6/4/2004, Goodwin Lawlor wrote:
>Hi All,
>
>I've got a class which uses this method in vtkOBBTree:
>
>int vtkOBBTree::IntersectWithOBBTree ( vtkOBBTree *, vtkMatrix4x4 *,
>int(*)(vtkOBBNode *, vtkOBBNode *, vtkMatrix4x4 *, void *), 
>void *)
>
>My code looks like:
>
>static int ComputeCollisions(vtkOBBNode *, vtkOBBNode *, vtkMatrix4x4 *,
>void *);
>  {
>  ...
>  }
>
>vtkCollisionDetectionFilter::Execute()
>  {
>  ...
>  Obbtree1->IntersectWithOBBTree ( Obbtree2, matrix, ComputeCollisions,
>this);
>  ...
>  }
>
>This works fine. Now I'd like to make ComputeCollisions a class member
>method but my compiler (bcc55) has other ideas. I get:
>
>Error E2034 vtkCollisionDetectionFilter.cxx 364: Cannot convert 'int (*
>(_closure )(vtkOBBNode *,vtkOBBNode *,vtkMatrix4x4 *,void *))(vtkOBBNode
>*,vtkOBBNode *,vtkMatrix4x4 *,void *)' to 'int (*)(vtkOBBNode
>*,vtkOBBNode *,vtkMatrix4x4 *,void *)' in function
>vtkCollisionDetectionFilter::Execute()
>
>Error E2342 vtkCollisionDetectionFilter.cxx 364: Type mismatch in
>parameter 'function' (wanted 'int (*)(vtkOBBNode *,vtkOBBNode
>*,vtkMatrix4x4 *,void *)', got 'void') in function
>vtkCollisionDetectionFilter::Execute()
>
>So I try:
>
>Obbtree1->IntersectWithOBBTree ( Obbtree2, matrix, (int
>(*))ComputeCollisions, this);
>
>And I get:
>
>Error E2235 vtkCollisionDetectionFilter.cxx 364: Member function must be
>called or its address taken in function
>vtkCollisionDetectionFilter::Execute()
>
>The source code for the class is here:
>http://www.bioengineering-research.com/vtk/vtkCollisionDetectionFilter.h
>tm
>
>
>Any help would be much appreciated.
>TIA,
>
>Goodwin
>
>
>_______________________________________________
>vtk-developers mailing list
>vtk-developers at vtk.org
>http://www.vtk.org/mailman/listinfo/vtk-developers 




More information about the vtk-developers mailing list