# vtkSmartPointer\<CMyClass\> does not compile

**URL:** <https://discourse.itk.org/t/vtksmartpointer-cmyclass-does-not-compile/2557>\
**Category:** Uncategorized\
**Created:** [December 20, 2019, 12:50pm UTC](https://discourse.itk.org/t/vtksmartpointer-cmyclass-does-not-compile/2557 "2019-12-20T12:50:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [December 20, 2019, 12:50pm UTC](https://discourse.itk.org/t/vtksmartpointer-cmyclass-does-not-compile/2557/1 "2019-12-20T12:50:30Z")

</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:

class vtkFile : public vtkObject {

private:  
std\>\>vectorstd::string s;

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

any suggestions appreciated!

Regards,  
sag

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [December 20, 2019, 2:29pm UTC](https://discourse.itk.org/t/vtksmartpointer-cmyclass-does-not-compile/2557/2 "2019-12-20T14:29:29Z")

</div>

In order to be wrapped into `vtkSmartPointer` (and `itk::SmartPointer`), a class must have public methods `Register()` and `UnRegister` which increase and decrease reference count. When created, objects have a reference count of one. Once the reference count reaches 0, the objects are to be de-allocated.

In case of deriving from `vtkObject`, you might need `vtkNew` macro and maybe some other stuff too. Instead of starting from scratch, take a similar existing class which derives from `vtkObject` and modify it.

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [December 20, 2019, 5:24pm UTC](https://discourse.itk.org/t/vtksmartpointer-cmyclass-does-not-compile/2557/3 "2019-12-20T17:24:38Z")

</div>

Hi @dzenanz,

Thanks, I know about reference count and register and unregister, I have used Unknown in days of ATL pop, and active, etc. by modifying you mean I drive from a class drived from vtkObject and then add my stuff in that include data members and public methods and protected, virtual, … and then it would be wrapped by vtkSmartPointer? do I need to call the class for instance vtkMyClass otherwise it would not be wrapped by vtkSmartPointer?

Regards,  
sag

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [December 20, 2019, 6:22pm UTC](https://discourse.itk.org/t/vtksmartpointer-cmyclass-does-not-compile/2557/4 "2019-12-20T18:22:41Z")

</div>

I don’t think it needs to be called vtkMyClass. The vtkName convention is purely for human benefit. I don’t know where `vtkTypeMacro` is defined, but look at a simple class like [vtkAppendPoints](https://gitlab.kitware.com/vtk/vtk/blob/master/Filters/General/vtkAppendPoints.h) to get a feel of what needs to be defined and how it looks like.
