[Insight-developers] Advice needed from C++ Template wizards.
kent williams
norman-k-williams at uiowa.edu
Tue Oct 26 12:36:53 EDT 2010
I'm trying to fix this bug:
http://public.kitware.com/Bug/view.php?id=3610
the problem is this code:
typename TFeatureImageType::Pointer tempFeature;
if ( typeid(TImageType) == typeid(TFeatureImageType))
{
m_Canny->SetInput(tempFeature);
}
else
{
m_Caster->SetInput(tempFeature);
m_Canny->SetInput(m_Caster->GetOutput());
}
This code breaks if typeid(TImageType) != typeid(TFeatureImageType), since
the compiler still compiles the top branch of the if statement, and the
m_Canny->SetInput() call will be in error because of incorrect parameter
type.
I thought I could fix this with specialization, like this:
> // IN CLASS DEFINITION
> template <class _TImageType, class _TFeatureImageType>
> void AssignCannyInput(typename _TFeatureImageType::Pointer &input)
> {
> m_Caster->SetInput(input);
> m_Canny->SetInput(m_Caster->GetOutput());
> }
> template <>
> void AssignCannyInput<TImageType,TImageType>(typename TImageType::Pointer
> &input)
> {
> m_Canny->SetInput(input);
> }
But the compiler objects to the specialization inside the class definition,
and moving the specialization out of the class like this:
> // Removed from class definition, moved to TXX file
> template< class TImageType, class TFeatureImageType >
> template <>
> void
> CannySegmentationLevelSetFunction< TImageType, TFeatureImageType >
> ::AssignCannyInput<TImageType,TImageType>
> (typename TImageType::Pointer &input)
> {
> m_Canny->SetInput(input);
> }
Is illegal as well.
Does anyone know of a good Template MetaProgramming solution to this issue?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20101026/21d4b214/attachment.htm>
More information about the Insight-developers
mailing list