[vtkusers] about the reference count

tom fogal tfogal at apollo.sr.unh.edu
Thu Apr 21 14:53:36 EDT 2005


 <000f01c54613$dc95e0a0$1f64a8c0 at YXLIU>Yixun Liu writes:
>Hi,
>
>Below is the source code of the VTK. I do not understand the code:   vtkRenderWindow *renWin = (vtkRenderWindow *)win.  Because it will cause error when win->MakeCUrrent() is calle
>d. Hope your help!

<snip>
>  vtkRenderWindow *renWin = (vtkRenderWindow *)win;
>
>  // pass this information onto the mapper
>  if (this->Mapper)
>    {
>    this->Mapper->ReleaseGraphicsResources(renWin);
>    }
<snip>

>void vtkOpenGLPolyDataMapper::ReleaseGraphicsResources(vtkWindow *win)
>{
>  if (this->ListId && win)
>    {
>    win->MakeCurrent();  ?????????(win belog to the vtkRenderWindow class and only has pure virtual method: MakeCurrent())
<snip>

This is an inheritance trick (actually, the main point of inheritance /
OO at least if you ask me). vtkWindow is an abstract class; all
subclasses must implement Makecurrent. The "win" being passed in is
known to not actually be a vtkWindow but one of its subclasses.

This will not cause an error. This will call the appropriate method
based on what "win" is at the exact time win->MakeCurrent() is called,
as opposed to what type it is at compile time, which is just vtkWindow
and (as you say) does not actually have any implementation.

Do a google for 'runtime dispatching', 'inheritance', 'polymorphism',
or similar for better explanations.

-tom



More information about the vtkusers mailing list