[vtkusers] vtkSmartPointer usage question

F frinxor at gmail.com
Fri Nov 6 18:17:41 EST 2009


I've been following along with this conversation and following the example
on the wiki, I tried to do this:

    vtkSmartPointer<vtkMultiBlockPLOT3DReader> m_Reader2;
    vtkSmartPointer<vtkMultiBlockDataSet> dataset = m_Reader2->GetOutput();

which gave me an error
 error C2664: 'vtkSmartPointerBase::vtkSmartPointerBase(vtkObjectBase *)' :
cannot convert parameter 1 from 'vtkMultiBlockDataSet *' to 'vtkObjectBase
*'

I can't seem to figure out why this is the case?


On Fri, Nov 6, 2009 at 4:03 PM, Alex Malyushytskyy <alexmalvtk at gmail.com>wrote:

> Jeff,
>
> > sp = NULL; // Release would happen here.
> That was what I was looking for.
> When I tried to look at the code I forgot that vtkSmartPointer is
> dialing with vtkObjectBase pointers.
>
> > Normally you just wait for the smart pointer to go out of scope.
>
> Main reason for me to use smartpointers - it helps dealing with
> exceptions especially thrown from constructors.
> So I usually use smart pointers as a class members instead of raw pointers
> .
> And even though smartpointer will do his job when it goes out of scope,
> you may get situation when you need to replace the data when it does not.
>
> Example:
> Assume poly data is read from the file and stored with smartpointer.
> User action changes the data (for example some additional tessellation).
> If result is satisfactory, old data should be replaced.
>
> Thanks everybody for help,
>              Alex
>
>
>
>
> On Fri, Nov 6, 2009 at 5:53 AM, Jeff Baumes <jeff.baumes at kitware.com>
> wrote:
> >> The only thing is  not clear  for me is how to force smartpointer to
> >> release the data.
> >>
> >
> > Is this what you're looking for?
> > vtkSmartPointer<vtkType> sp = vtkSmartPointer<vtkType>::New();
> > ...
> > sp = NULL; // Release would happen here.
> > This would decrement the reference count of the object by one. If no one
> > else holds a reference count of the object (i.e. reference count goes to
> > zero), it will be released from memory.
> > Normally you just wait for the smart pointer to go out of scope. If you
> > explicitly need to make the reference go away at a certain point, you
> might
> > as well not use smart pointers and just do this equivalent code:
> > vtkType* p = vtkType::New();
> > ...
> > p->Delete();
> > Jeff
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091106/269becf2/attachment.htm>


More information about the vtkusers mailing list