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

Luis Ibanez luis . ibanez at kitware . com
Sat, 13 Jul 2002 09:23:28 -0400


Hi Suzanne,

Thanks for clarifying your question.

I'm affraid that the array of objects cannot be declared.

The constructors of many ITK classes have been declared
protected with the full intention of preventing users
from doing what you are trying to do.

The reason is that by instantiating objects directly,
(even if they are not in an array) you will not be able
to introduce the use of alternative factories and you
will also disrupt the mechanism of reference counting
that allows these objects to be shared.


Possible options for the array of objects are:

1) Array of raw pointers
2) Array of SmartPointers
3) Array of AutoPointers
    (though our autopointers are a bit nonstandard)


If performance is a concern, (1) could be your best bet.



  Luis


=============================================================

Suzanne Vogel wrote:

> Hi Luis and fellow ITK users,
> 
> Thank you, Luis, I did learn something from your e-mail. However, I 
> think I used the wrong terminology in my previous e-mail. Where I said 
> "references," I mean "objects."
> 
> I want to create an array of ITK *objects* (not references). However, 
> the following syntax does not compile, where Foo is a typical ITK class 
> derived from LightObject so that it can take advantage of creation by 
> ObjectFactory:
> 
> Foo array = new Foo[N];
> /* Note: I'm not asking about "new Foo&[N]," which Luis thought I was */
> 
> I believe that this syntax does not compile because the constructor of 
> these objects is protected, as required by ObjectFactory. The compiler 
> error *is* something like "cannot access protected member Foo() of class 
> Foo," indicating that the compiler is trying to call the Foo constructor.
> 
> Suzanne
>