[Insight-developers] Code/Review/itkOptImageToImageMetric strange const issues
kent williams
norman-k-williams at uiowa.edu
Wed Oct 14 11:38:33 EDT 2009
I just checked in a change to Code/Review/itkOptImageToImageMetric.txx that
quiets a warning:
Insight/Code/Review/itkOptImageToImageMetric.txx:1210: warning: cast from
`const itk::ImageToImageMetric<itk::Image<float, 3u>, itk::Image<float, 3u>
>::MultiThreaderParameterType*' to `void*' discards qualifiers from pointer
target type
There are 3 instances of this warning in that file. The problem is methods
like this:
template < class TFixedImage, class TMovingImage >
void
ImageToImageMetric<TFixedImage,TMovingImage>
::GetValueMultiThreadedPreProcessInitiate( void ) const
{
this->SynchronizeTransforms();
m_Threader->SetSingleMethod(GetValueMultiThreadedPreProcess,
(void *)(&m_ThreaderParameter));
m_Threader->SingleMethodExecute();
}
I believe the warning comes from the method being tagged as const. This
seems weird to me for several reasons:
1. Even if it doesn't directly modify a class member, it's passing the
address of a class member to a second object, which may then modify it.
2. Why are we still using C-style casts?
3. Calling non-const methods on a member variable in a const class method
constitute modifying class state -- why are the calls to SetSingleMethod not
flagged as violations of the method's const-ness
The fix I checked in addresses the warning by nesting a static_cast to const
void * inside a const_cast to void *. That silences the warning, but the
whole thing looks fishy to me.
More information about the Insight-developers
mailing list