# Return type relying on template-dependant value?

**URL:** https://discourse.itk.org/t/return-type-relying-on-template-dependant-value/450
**Category:** Engineering
**Created:** [November 22, 2017, 4:04pm UTC](https://discourse.itk.org/t/return-type-relying-on-template-dependant-value/450 "2017-11-22T16:04:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tim-evain](https://discourse.itk.org/user_avatar/discourse.itk.org/tim-evain/32/220_2.png) [@tim-evain](https://discourse.itk.org/u/tim-evain)
#### Post date: [November 22, 2017, 4:04pm UTC](https://discourse.itk.org/t/return-type-relying-on-template-dependant-value/450/1 "2017-11-22T16:04:32Z")

</div>

Hello everyone !

I try to create my own itk filter based on the ImageToImageFilter. Following the guideline, we could access to the run-time image dimension with TInputImage::ImageDimension or with the help of the itkSetStaticConstMacro for the members variables or into members functions.

But I want to have functions with return type based on this ImageDimension, for example :  
itk::Image\<float, TInputImage::ImageDimension\>::Pointer CreateDeepCopy(itk::Image\<float, TInputImage::ImageDimension\>::Pointer InputImage)  
{  
// … processing  
// return pointer  
}

This does not compile, as ImageDimension is not recognized properly into the return type :  
" error C2146: syntax error : missing ‘;’ before identifier ‘CreateDeepCopy’ "

How can I correct that ?

Tim

---

<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: [November 22, 2017, 7:50pm UTC](https://discourse.itk.org/t/return-type-relying-on-template-dependant-value/450/2 "2017-11-22T19:50:46Z")

</div>

If I remember correctly, it is a limitation of type inference system in the compilers. The workaround is to declare the method bypassing the Pointer `typedef`. Something like this:

```
itk::SmartPointer<itk::Image<float, TInputImage::ImageDimension> > CreateDeepCopy(itk::SmartPointer<itk::Image<float, TInputImage::ImageDimension> > InputImage)
{
// … processing
// return pointer
}
```

---

<div class="post-metadata">

### Author: ![tim-evain](https://discourse.itk.org/user_avatar/discourse.itk.org/tim-evain/32/220_2.png) [@tim-evain](https://discourse.itk.org/u/tim-evain)
#### Post date: [November 22, 2017, 8:33pm UTC](https://discourse.itk.org/t/return-type-relying-on-template-dependant-value/450/3 "2017-11-22T20:33:45Z")

</div>

Thanks Dženan, it works perfectly now !
