# Does an efficient cloning of multiple different classes with an override of InternalClone() exist?

**URL:** https://discourse.itk.org/t/does-an-efficient-cloning-of-multiple-different-classes-with-an-override-of-internalclone-exist/1109
**Category:** Algorithms
**Tags:** clone
**Created:** [July 11, 2018, 12:35pm UTC](https://discourse.itk.org/t/does-an-efficient-cloning-of-multiple-different-classes-with-an-override-of-internalclone-exist/1109 "2018-07-11T12:35:09Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [July 18, 2018, 1:14pm UTC](https://discourse.itk.org/t/does-an-efficient-cloning-of-multiple-different-classes-with-an-override-of-internalclone-exist/1109/8 "2018-07-18T13:14:24Z")

</div>

> [@Gordian](#):
>
> using MetricBasePointer = MetricBaseType\*;

This will be problematic in your use case: `std::vector<MetricBasePointer> m_MetricVector;`. A smart pointer should be used so a reference is kept to the object. That is,

```auto
using MetricBasePointer = MetricBaseType::Pointer;

```

> [@Gordian](#):
>
> std::cout \<\< dynamic\_cast\<MIMetricType\*\>m\_MetricVector.at(i)-\>GetNameOfClass() \<\< std::endl;

After fixing the issue identified above, what is the output of this?

> [@Gordian](#):
>
> Why should the function return a LightObject::Pointer instead of an pointer of the object.

The function has the same function signature for polymorphism.

---

_[View the full topic](https://discourse.itk.org/t/does-an-efficient-cloning-of-multiple-different-classes-with-an-override-of-internalclone-exist/1109)._
