[Insight-users] Ref. Smart pointers as function argument
Luis Ibanez
luis.ibanez at kitware.com
Mon Nov 23 10:34:34 EST 2009
Hi Ricardo,
Yes, you could use the signature:
> InputType::Pointer filtering( InputType::Pointer input, Arg1Type,
> Arg2Type )
instead of the signature:
> InputType::Pointer filtering( const InputType * input, Arg1Type,
> Arg2Type )
But then your Function will NOT be able to accept as first arguments,
objects whose class derive from the InputType class.
That is, SmartPointers won't manage polymorphism.
Additionally, passing the SmartPointer by copy will result in transitory
changes to the reference counting, that include a Mutex lock call.
Should you decide to use the SmartPointer as the argument type,
at least you should pass it by reference, as in:
> InputType::Pointer filtering( InputType::Pointer & input, Arg1Type,
> Arg2Type )
and probably should be a "const" type, since the input is not supposed
to be modified.
The standard practice in ITK is to pass as input:
const raw pointers
but, of course,
you may have motives for using a different approach.
Regards,
Luis
--------------------------------------------
On Sun, Nov 22, 2009 at 4:34 PM, Ricardo Ferrari
<ricardo.jose.ferrari at gmail.com> wrote:
> Hi Luiz,
>
> Just a quick question. In regarding to passing smart pointers as function
> argument, would be also okay to do the following ?
>
> ///InputType::Pointer filtering( const InputType * input, Arg1Type,
> Arg2Type )
>
> InputType::Pointer filtering( InputType::Pointer input, Arg1Type,
> Arg2Type )
> {
> ....
>
> filter->SetInput( input );
> filter->Update();
> InputType::Pointer output = filter->GetOutput();
> output->DisconnectPipeline();
> return output;
> }
>
>
More information about the Insight-users
mailing list