Skip to content

Commit 9120566

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 9120566

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

Modules/Core/Common/include/itkImageSource.hxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ 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+
44+
// Equivalent to SetNthOutput(0, MakeOutput(0)); in this case, calling MakeOutput is not necessary.
45+
this->ProcessObject::SetNthOutput(0, TOutputImage::New());
4746

4847
#if defined(ITKV4_COMPATIBILITY)
4948
m_DynamicMultiThreading = false;

Modules/Core/Mesh/include/itkImageToMeshFilter.hxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ 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+
32+
// Equivalent to SetNthOutput(0, MakeOutput(0)); in this case, calling MakeOutput is not necessary.
33+
this->ProcessObject::SetNthOutput(0, OutputMeshType::New());
3534
}
3635

3736
/**

Modules/Core/Mesh/include/itkMeshSource.hxx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ 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+
30+
// Equivalent to SetNthOutput(0, MakeOutput(0)); in this case, calling MakeOutput is not necessary.
31+
this->ProcessObject::SetNthOutput(0, TOutputMesh::New());
3432

3533
m_GenerateDataRegion = 0;
3634
m_GenerateDataNumberOfRegions = 0;

0 commit comments

Comments
 (0)