[Insight-users] const correctness

Henning Meyer tutmann at gmail.com
Mon Jun 26 02:41:19 EDT 2006


But why not:

template <class TObjectType>
SmartPointer::operator SmartPointer<const ObjectType> (const SmartPointer &r) {
  return SmartPointer<const ObjectType>((const ObjectType)r.m_Pointer);
}


2006/6/22, Karthik Krishnan <Karthik.Krishnan at kitware.com>:
> Henning Meyer wrote:
>
> > Ok, thanks.
> > Why isn't there an
> >
> > itk::Object::Pointer::operator
> > itk::Object::ConstPointer(itk::Object::Pointer x)
> > ?
>
> Its a lot more complicated than that... You cannot achieve this by this
> kind of a copy constructor
>
> XXX::Pointer   is just a typedef to  itk::SmartPointer< XXX > *
> XXX::ConstPointer === itk::SmartPointer< const XXX > *
>
> So you are asking for a copy constructor inside the itk::SmartPointer< T
>  > class that can cast from a non-const version of T to a const version
> of T.
>
> There are ways to do what you want with partial specialization as in
> defining a class
> itk::SmartPointer< T >
> and specializing
>   itk::SmartPointer< const T >
>
> but partial specialization is not supported by legacy compilers like VC6.0
>
> >
> > I'm not an expert, but couln't this be accomplished by itkNewMacro or
> > itkTypeMacro or something similar?
> >
> > Or is const correctness something itk does not care about?
> >
> > Henning
> >
> >
> >
> > 2006/6/22, Karthik Krishnan <Karthik.Krishnan at kitware.com>:
> >
> >> On Wed, 2006-06-21 at 11:01 +0200, Henning Meyer wrote:
> >> > Hello,
> >> >
> >> > why does a cast from XXX::Pointer to XXX::ConstPointer not happen
> >> automatically?
> >> > How do I cast correctly?
> >>
> >> XXX::Pointer p = XXX::New();
> >> XXX::ConstPointer  = p.GetPointer();
> >>
> >> > Henning
> >> > _______________________________________________
> >> > Insight-users mailing list
> >> > Insight-users at itk.org
> >> > http://www.itk.org/mailman/listinfo/insight-users
> >>
> >>
> >
>


More information about the Insight-users mailing list