# invalid use of incomplete type ‘class vtkPolyData’

**URL:** https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337
**Category:** Support
**Created:** [July 15, 2019, 3:28pm UTC](https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337 "2019-07-15T15:28:22Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![nicoco](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/7c8e57/32.png) [@nicoco](https://discourse.vtk.org/u/nicoco)
#### Post date: [July 15, 2019, 3:28pm UTC](https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337/1 "2019-07-15T15:28:22Z")

</div>

Hello everyone,

I would like to test whether an array is present in a polydata, but I am getting this error at compile time:

```
NicocoTest.cxx:10:39: error: invalid use of incomplete type ‘class vtkPolyData’
   if (reader.GetPointer()->GetOutput()->GetPointData()->HasArray("ARRAYNAME")) {
                                       ^~
In file included from NicocoTest.cxx:1: VTK-8.2.0/IO/Legacy/vtkPolyDataReader.h:37:7: note: forward declaration of ‘class vtkPolyData’
 class vtkPolyData;
       ^ ~~~~~~~~~~

```

Here is the source code leading to this hard-to-understand-for-c++-noob error:

```
#include "vtkPolyDataReader.h"
#include "vtkNew.h"

int main(int argc, char *argv[]) {
  std::cout << "Reading file" << std::endl;
  
  vtkNew<vtkPolyDataReader> reader;
  reader->SetFileName(argv[1]);

  if (reader.GetPointer()->GetOutput()->GetPointData()->HasArray("ARRAYNAME")) {
    std:cout << "An array named ARRAYNAME was found" << std::endl;
  }

  return EXIT_SUCCESS;
}

```

What am I doing wrong? What would be the correct way of avoid this error?

Thank you very much.

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/danlipsa/32/390_2.png) [@danlipsa](https://discourse.vtk.org/u/danlipsa)
#### Post date: [July 15, 2019, 4:00pm UTC](https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337/2 "2019-07-15T16:00:22Z")

</div>

I think you’ll have to

#include “vtkPolyData.h”

---

<div class="post-metadata">

### Author: ![lplavorante](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lplavorante/32/272_2.png) [@lplavorante](https://discourse.vtk.org/u/lplavorante)
#### Post date: [July 15, 2019, 4:13pm UTC](https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337/3 "2019-07-15T16:13:22Z")

</div>

Nicoco, after

reader-\>SetFileName(argv[1]);

insert the line

reader-\>Update();

This method is necessary to actually perform the reading and update correctly reader-\>GetOutput().

One question: what are you going to do with reader-\>GetOutput() ?  
Maybe, you could do something like (this will copy your data):

vtkNew\< vtkPolyData \> polyData;  
polyData-\>DeepCopy(reader-\>GetOutput());

Or simply

vtkSmartPointer\< vtkPolyData \> polyData = reader-\>GetOutput(); // No copy here

And then use the object ’ polyData’ for the rest of your processing / visualization pipeline.

Hope this help.

```
    Luca
```

---

<div class="post-metadata">

### Author: ![nicoco](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/7c8e57/32.png) [@nicoco](https://discourse.vtk.org/u/nicoco)
#### Post date: [July 16, 2019, 6:08am UTC](https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337/4 "2019-07-16T06:08:02Z")

</div>

Thank you for your help. Unfortunately, this does not solve the compile-time issue at all. I first tried just adding `include`. Here is what the code looks like now:

```
#include "vtkPolyDataReader.h"
#include "vtkNew.h"
#include "vtkPolyData.h"

int main(int argc, char *argv[]) {
  std::cout << "Reading file" << std::endl;
  
  vtkNew<vtkPolyDataReader> reader;
  reader->SetFileName(argv[1]);
  reader->Update();

  vtkSmartPointer< vtkPolyData > polyData = reader->GetOutput();

  int hasArray = polyData->GetPointData()->HasArray("ARRAYNAME");

  if (hasArray) {
    std:cout << "An array named ARRAYNAME was found" << std::endl;
  }

  return EXIT_SUCCESS;
}

```

and the error:

```
NicocoTest.cxx: In function ‘int main(int, char**)’:
NicocoTest.cxx:14:42: error: invalid use of incomplete type ‘class vtkPointData’
   int hasArray = polyData->GetPointData()->HasArray("ARRAYNAME");
                                          ^~
In file included from VTK-8.2.0/Common/DataModel/vtkPointSet.h:33,
                 from Common/DataModel/vtkPolyData.h:62,
                 from NicocoTest.cxx:3:
VTK-8.2.0/Common/DataModel/vtkDataSet.h:52:7: note: forward declaration of ‘class vtkPointData’
 class vtkPointData;
       ^ ~~~~~~~~~~~
make[2]: *** [nicoco/CMakeFiles/NicocoTest.dir/build.make:63: nicoco/CMakeFiles/NicocoTest.dir/NicocoTest.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1233: nicoco/CMakeFiles/NicocoTest.dir/all] Error 2
make: *** [Makefile:95: all] Error 2

```

What I am trying to achieve seems so basic…

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [July 16, 2019, 8:39am UTC](https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337/5 "2019-07-16T08:39:25Z")

</div>

> [@nicoco](#):
>
> error: invalid use of incomplete type ‘class vtkPointData’

This error pretty much always means that header inclusions are missing. In VTK, the header name is (in the vast majority of cases) `classname.h`, so here, adding `#include "vtkPointData.h"` would make the class declaration available.

---

<div class="post-metadata">

### Author: ![nicoco](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/7c8e57/32.png) [@nicoco](https://discourse.vtk.org/u/nicoco)
#### Post date: [July 16, 2019, 8:57am UTC](https://discourse.vtk.org/t/invalid-use-of-incomplete-type-class-vtkpolydata/1337/6 "2019-07-16T08:57:04Z")

</div>

Thank you very much @ben.boeckel

That was it!
