[Insight-users] arrays of ITK objects w/ protected constructors

Suzanne Vogel vogel at cs . unc . edu
Fri, 12 Jul 2002 20:40:24 -0400


** Is there a way to declare an array of references (not pointers) to 
ITK objects whose contructors are protected?

Often constructors are protected to enable creation by ObjectFactory.

Example:

template <typename foo>
class Foo : public LightObject
{  public:
      /* definitions necessary for creation by ObjectFactory */
      ...
    protected:
      Foo();
      ...
}

#include "itkFoo.h"
void main(int argc, char **argv)
{  Foo *array1 = new Foo[N];
    /* array of references - does not compile */
    /* compiler error: cannot access protected Foo constructor */

    Foo **array2 = new Foo*[N];
    /* array of pointers - works but is ugly */

    Foo array3 = new ((Foo::New())->GetReference)[N];
    / *attempt at array of references - does not compile */
}

Maybe I'll compromise by making an array of SmartPointers to Foo. :(

Thanks,
Suzanne