# vtkSmartPointer\<MyClass\>

**URL:** https://discourse.vtk.org/t/vtksmartpointer-myclass/2321
**Category:** Support
**Created:** [December 20, 2019, 12:44pm UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321 "2019-12-20T12:44:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Sohrab\_Azami](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sohrab_azami/32/1210_2.png) [@Sohrab\_Azami](https://discourse.vtk.org/u/Sohrab_Azami)
#### Post date: [December 20, 2019, 12:44pm UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321/1 "2019-12-20T12:44:59Z")

</div>

Hi,

I would like to pass a regular c++ class to my vtkSmartPointer object, obviously I have difficulty to compile it! What I did I drived it from vtkObject  
class:

```auto
class vtkFile : public vtkObject {

private:
std>>vector<std::string> s;

public:
     vtkFile(). : s({1","2"}){}
     ~vtkFile(){}
};

```

I still get errors :  
canot convert from ‘initializer list’ to 'vtkSmartPointer  
no constructor could take the source the, or constructor overload was ambigious

Any help appreciated!

Regards,  
sag

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [December 20, 2019, 4:00pm UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321/2 "2019-12-20T16:00:59Z")

</div>

I don’t see any code involving a vtkSmartPointer here.  
Moreover, constructor/destructor should be protected, and you have to use `vtkTypeMacro(vtkFile, vtkObject);`.  
Have a look at any existing vtk class.

---

<div class="post-metadata">

### Author: ![Sohrab\_Azami](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sohrab_azami/32/1210_2.png) [@Sohrab\_Azami](https://discourse.vtk.org/u/Sohrab_Azami)
#### Post date: [December 20, 2019, 6:03pm UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321/3 "2019-12-20T18:03:19Z")

</div>

Hi Michael,

I am trying to use vtkTypeMacro but I cannot find the header for this ? would you by any chance know what it is, I get compiler error visual studio 2017!

Regards,  
sag

---

<div class="post-metadata">

### Author: ![Sohrab\_Azami](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sohrab_azami/32/1210_2.png) [@Sohrab\_Azami](https://discourse.vtk.org/u/Sohrab_Azami)
#### Post date: [December 21, 2019, 7:46am UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321/4 "2019-12-21T07:46:12Z")

</div>

Hi Michael,

I did find the vtkTest example and I am working on that, it is compiling now. I appreciate you attention to this question

Regards,  
sag

---

<div class="post-metadata">

### Author: ![Cheng1087](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cheng1087/32/1197_2.png) [@Cheng1087](https://discourse.vtk.org/u/Cheng1087)
#### Post date: [December 21, 2019, 1:57pm UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321/5 "2019-12-21T13:57:34Z")

</div>

vtkTypeMacro is in vtkSetGet.h

---

<div class="post-metadata">

### Author: ![Sohrab\_Azami](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sohrab_azami/32/1210_2.png) [@Sohrab\_Azami](https://discourse.vtk.org/u/Sohrab_Azami)
#### Post date: [December 24, 2019, 8:15am UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321/6 "2019-12-24T08:15:16Z")

</div>

Thanks Cheng!

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [July 22, 2020, 4:41pm UTC](https://discourse.vtk.org/t/vtksmartpointer-myclass/2321/7 "2020-07-22T16:41:31Z")

</div>

Can you possibly share your code please? I am having trouble doing this also.  
Thanks!
