[Insight-developers] inheritance

Peter Cech pcech at vision.ee.ethz.ch
Sat May 26 04:09:22 EDT 2007


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



More information about the Insight-developers mailing list