[vtkusers] Forward declaration of Foo enough for vtkNew<Foo> declaration?

Elvis Stansvik elvis.stansvik at orexplore.com
Wed Aug 10 10:51:01 EDT 2016


2016-08-10 15:44 GMT+02:00 Shawn Waldon <shawn.waldon at kitware.com>:

> Hi Elvis,
>
> The problem is this:  Declaring vtkNew<Foo> should be fine when Foo is
> forward declared.  But when the vtkNew<Foo> is deleted in your destructor,
> the vtkNew<Foo>'s destructor needs to call Foo->Delete().  So at that point
> it needs the full definition of Foo.  In your example, if you declare your
> class's destructor and implement it as {} (use the default) in an
> implementation file where Foo's header is included this should work.  One
> of my projects uses vtkNew this way.
>

Thanks Shawn, that was indeed the problem. Adding empty destructors did the
trick.

Elvis


>
> HTH,
> Shawn
>
> On Wed, Aug 10, 2016 at 8:39 AM, Elvis Stansvik <
> elvis.stansvik at orexplore.com> wrote:
>
>> 2016-08-10 14:32 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
>>
>>> Hi,
>>>
>>> The overview at
>>>
>>>     https://blog.kitware.com/a-tour-of-vtk-pointer-classes/
>>>
>>> seems to suggest that forward declaration of a class Foo should be
>>> enough to be able to declare a vtkNew<Foo> (e.g. see how vtkTable is used
>>> in the code example under "Use of Classes").
>>>
>>> But when I try e.g:
>>>
>>> class vtkCompositeTransferFunctionItem;
>>> ...
>>> vtkNew<vtkCompositeTransferFunctionItem> m_functionsItem;
>>>
>>> I get
>>>
>>>     error: invalid use of incomplete type ‘class
>>> vtkCompositeTransferFunctionItem’
>>>
>>> Do I really need to include vtkCompositeTransferFunctionItem.h to
>>> declare a vtkNew<vtkCompositeTransferFunctionItem> ?
>>>
>>
>> To show more of the context where I'm trying this:
>>
>> #pragma once
>>
>> #include "VTKWidget.h"
>>
>> #include <QObject>
>> #include <Qt>
>>
>> #include <vtkNew.h>
>>
>> #include <vtkChartXY.h>
>> #include <vtkContextView.h>
>> #include <vtkCompositeControlPointsItem.h>
>> #include <vtkCompositeTransferFunctionItem.h>
>>
>> class QWidget;
>>
>> class vtkColorTransferFunction;
>> // Apparently I can't just forward declare these.
>> //class vtkChartXY;
>> //class vtkCompositeTransferFunctionItem;
>> //class vtkCompositeControlPointsItem;
>> //class vtkContextView;
>> class vtkPiecewiseFunction;
>>
>> class CompositeTransferFunctionEditor : public VTKWidget
>> {
>>     Q_OBJECT
>>
>> public:
>>     enum Mode {
>>         EditColor,
>>         EditOpacity
>>     };
>>     Q_ENUM(Mode)
>>
>> public:
>>     CompositeTransferFunctionEditor(vtkColorTransferFunction
>> *colorFunction,
>>                                     vtkPiecewiseFunction
>> *opacityFunction,
>>                                     Mode mode = EditColor,
>>                                     QWidget *parent = 0,
>>                                     Qt::WindowFlags flags =
>> Qt::WindowFlags());
>>
>>     void setColorFunction(vtkColorTransferFunction *colorFunction);
>>     void setOpacityFunction(vtkPiecewiseFunction *opacityFunction);
>>
>> signals:
>>     void functionsModified();
>>
>> private:
>>     void editColorPoint();
>>
>> private:
>>     vtkNew<vtkCompositeTransferFunctionItem> m_functionsItem;
>>     vtkNew<vtkCompositeControlPointsItem> m_pointsItem;
>>     vtkNew<vtkChartXY> m_chart;
>>     vtkNew<vtkContextView> m_contextView;
>> };
>>
>> I had hoped I would only have to forward declare the types used in the
>> instantiations of vtkNew here, not include the full headers.
>>
>> Elvis
>>
>>
>>> Thanks,
>>> Elvis
>>>
>>
>>
>> _______________________________________________
>> 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
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160810/d8d89dee/attachment.html>


More information about the vtkusers mailing list