[Insight-developers] inheritance

Luis Ibanez luis.ibanez at kitware.com
Sun May 27 10:32:48 EDT 2007


Hi Debbie,

Please not that if your derived class is a templated class,
then you still need to add the "typename" keyword to your
declaration.


Like:

    typedef  typename Superclass::IndexType    IndexType

not just:

    typedef           Superclass::IndexType    IndexType




If you are using a recent CVS checkout of ITK,
then you can take advantage of the macro:


         itkSuperclassTraits( IndexType );


for generating the correct typedef.




Regards,


    Luis


------------------
Peter Cech wrote:
> On Sat, May 26, 2007 at 02:24:04 +0000, debbie larson wrote:
> 
>>Hi,
>>
>>This is a basic question on inheritance but I am stuck. I wrote a class 
>>that inherits from FloodFilledFunctionConditionalConstIterator. Thus in the 
>>.h file I wrote
>>
>>template<class TImage, class TFunction>
>>class ITK_EXPORT FloodFilledFunctionConditionalConstIterator2:
>>   public FloodFilledFunctionConditionalConstIterator<TImage,TFunction>
>>
>>Now the parent class has several typedefs that I would like to use in the 
>>child class. For example it has
>>
>>  typedef typename TImage::IndexType  IndexType;
>>
>>How do I use IndexType in the child class?
>>
>>I tried
>>
>>const IndexType & topIndex = m_IndexStack.front();
>>
>>then I tried
>>
>>const Superclass::IndexType & topIndex = m_IndexStack.front();
> 
> 
> As for the type the above should work. You can do
> 
>   typedef Superclass::IndexType    IndexType
> 
> for convenience. Another thing that can go wrong is access to
> Superclass' member variables. One has to access them via this->
> 
>   const Superclass::IndexType & topIndex = this->m_IndexStack.front();
> 
> This is requirement of C++ standard - AFAIK only for inheriting
> templated classes, but does not hurt if you use it everywhere.
> 
> If there are still problems, post the relevant code and compiler error.
> 
> Regards,
> Peter
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
> 


More information about the Insight-developers mailing list