[Insight-users] C2440 when reinterpret_cast-ing from base to specific class

Michael Jackson mike.jackson at bluequartz.net
Wed Dec 16 15:27:58 EST 2009


My guess is that the compiler doesn't like trying to cast a "smart  
pointer" from one thing to another. You probably really want to cast  
the optimizer.GetPointer()

> reinterpret_cast<GradientDescentType*>(optimizer.GetPointer())- 
> >SetRelaxationFactor(0.5);

> itk::SingleValuedNonLinearOptimizer::Pointer is NOT a normal pointer.

HTH
_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio

On Dec 16, 2009, at 3:10 PM, itkvtk123 at gmx.net wrote:

> Hello itk users!
>
> Today I encountered a very simple problem but I could not find out  
> what I'm doing wrong.
> I want to convert a base class object to the specific class, but it  
> does not seem to work.
>
> I'm getting
> "error C2440: 'reinterpret_cast' : cannot convert from  
> 'itk::SingleValuedNonLinearOptimizer::Pointer' to  
> 'itk::RegularStepGradientDescentOptimizer::Pointer"
>
>
> Minimal Code:
>
> ///////////////////////////////////////////////////////////////////////////////////////////
>
> #include "itkSingleValuedNonLinearOptimizer.h"
> #include "itkRegularStepGradientDescentOptimizer.h"
>
> int main()
> {
> 	typedef itk::SingleValuedNonLinearOptimizer OptimizerType;
> 	typedef itk::RegularStepGradientDescentOptimizer GradientDescentType;
>
> 	OptimizerType::Pointer optimizer = GradientDescentType::New();
>
> 	reinterpret_cast<GradientDescentType::Pointer>(optimizer)- 
> >SetRelaxationFactor(0.5);
>
> 	return 0;
> }
>
> ///////////////////////////////////////////////////////////////////////////////////////////
>
>
> Since RegularStepGradientDescentOptimizer is a child class from  
> SingleValuedNonLinearOptimizer, I do not understand why this  
> conversion does not work.
>
> Any help appreciated!
> -- 
> Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla  
> Firefox 3.5 -
> sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list