Skip to content

Commit 6124014

Browse files
committed
STYLE: Remove this->MakeOutput(0) calls from constructors in Core
In those cases, `MakeOutput(0)` just did `OutputType::New()` anyway. This commit avoids unnecessary casts and calls to virtual functions. 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
1 parent 28de861 commit 6124014

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

Modules/Core/Common/include/itkImageSource.hxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ namespace itk
3939
template <typename TOutputImage>
4040
ImageSource<TOutputImage>::ImageSource()
4141
{
42-
// Create the output. We use static_cast<> here because we know the default
43-
// output must be of type TOutputImage
44-
typename TOutputImage::Pointer output = static_cast<TOutputImage *>(this->MakeOutput(0).GetPointer());
4542
this->ProcessObject::SetNumberOfRequiredOutputs(1);
46-
this->ProcessObject::SetNthOutput(0, output.GetPointer());
43+
this->ProcessObject::SetNthOutput(0, TOutputImage::New().GetPointer());
4744

4845
#if defined(ITKV4_COMPATIBILITY)
4946
m_DynamicMultiThreading = false;

Modules/Core/Mesh/include/itkImageToMeshFilter.hxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ template <typename TInputImage, typename TOutputMesh>
2727
ImageToMeshFilter<TInputImage, TOutputMesh>::ImageToMeshFilter()
2828
{
2929
this->ProcessObject::SetNumberOfRequiredInputs(1);
30-
31-
OutputMeshPointer output = dynamic_cast<OutputMeshType *>(this->MakeOutput(0).GetPointer());
32-
3330
this->ProcessObject::SetNumberOfRequiredOutputs(1);
34-
this->ProcessObject::SetNthOutput(0, output.GetPointer());
31+
this->ProcessObject::SetNthOutput(0, OutputMeshType::New().GetPointer());
3532
}
3633

3734
/**

Modules/Core/Mesh/include/itkMeshSource.hxx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ namespace itk
2525
template <typename TOutputMesh>
2626
MeshSource<TOutputMesh>::MeshSource()
2727
{
28-
// Create the output. We use static_cast<> here because we know the default
29-
// output must be of type TOutputMesh
30-
OutputMeshPointer output = static_cast<TOutputMesh *>(this->MakeOutput(0).GetPointer());
31-
3228
this->ProcessObject::SetNumberOfRequiredOutputs(1);
33-
this->ProcessObject::SetNthOutput(0, output.GetPointer());
29+
this->ProcessObject::SetNthOutput(0, TOutputMesh::New().GetPointer());
3430

3531
m_GenerateDataRegion = 0;
3632
m_GenerateDataNumberOfRegions = 0;

0 commit comments

Comments
 (0)