From 637cf0202049678be5fe2e01aa91f18739089c36 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 10 May 2024 15:09:54 +0200 Subject: [PATCH] STYLE: Remove `this->MakeOutput(0)` calls from constructors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Analogue to ITK pull request https://github.com/InsightSoftwareConsortium/ITK/pull/4654 Following C++ Core Guidelines, February 15, 2024, "Don’t call virtual functions in constructors and destructors", https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-ctor-virtual --- Common/ImageSamplers/itkImageSamplerBase.hxx | 5 +---- Common/ImageSamplers/itkVectorContainerSource.hxx | 6 +----- Common/itkMultiResolutionImageRegistrationMethod2.hxx | 4 +--- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Common/ImageSamplers/itkImageSamplerBase.hxx b/Common/ImageSamplers/itkImageSamplerBase.hxx index 28738facd..103eae733 100644 --- a/Common/ImageSamplers/itkImageSamplerBase.hxx +++ b/Common/ImageSamplers/itkImageSamplerBase.hxx @@ -405,11 +405,8 @@ template ImageSamplerBase::ImageSamplerBase() { this->ProcessObject::SetNumberOfRequiredInputs(1); - - OutputVectorContainerPointer output = dynamic_cast(this->MakeOutput(0).GetPointer()); - this->ProcessObject::SetNumberOfRequiredOutputs(1); - this->ProcessObject::SetNthOutput(0, output.GetPointer()); + this->ProcessObject::SetNthOutput(0, OutputVectorContainerType::New().GetPointer()); } // end Constructor diff --git a/Common/ImageSamplers/itkVectorContainerSource.hxx b/Common/ImageSamplers/itkVectorContainerSource.hxx index 0d1079c7a..b4ee7ca37 100644 --- a/Common/ImageSamplers/itkVectorContainerSource.hxx +++ b/Common/ImageSamplers/itkVectorContainerSource.hxx @@ -30,12 +30,8 @@ namespace itk template VectorContainerSource::VectorContainerSource() { - // Create the output. We use static_cast<> here because we know the default - // output must be of type TOutputVectorContainer - OutputVectorContainerPointer output = static_cast(this->MakeOutput(0).GetPointer()); - this->ProcessObject::SetNumberOfRequiredOutputs(1); - this->ProcessObject::SetNthOutput(0, output.GetPointer()); + this->ProcessObject::SetNthOutput(0, TOutputVectorContainer::New().GetPointer()); this->m_GenerateDataRegion = 0; this->m_GenerateDataNumberOfRegions = 0; diff --git a/Common/itkMultiResolutionImageRegistrationMethod2.hxx b/Common/itkMultiResolutionImageRegistrationMethod2.hxx index e5b44555e..5cef1fb6c 100644 --- a/Common/itkMultiResolutionImageRegistrationMethod2.hxx +++ b/Common/itkMultiResolutionImageRegistrationMethod2.hxx @@ -79,9 +79,7 @@ MultiResolutionImageRegistrationMethod2::MultiResolut this->m_InitialTransformParametersOfNextLevel.Fill(0.0f); this->m_LastTransformParameters.Fill(0.0f); - TransformOutputPointer transformDecorator = static_cast(this->MakeOutput(0).GetPointer()); - - this->ProcessObject::SetNthOutput(0, transformDecorator.GetPointer()); + this->ProcessObject::SetNthOutput(0, TransformOutputType::New().GetPointer()); } // end Constructor