Skip to content

Commit 6d8d304

Browse files
committed
ENH: ITKv5 override consistency
Provide remove virtual and override Use clang-tidy to add ITK_OVERRIDE, and to remove redundant virtual on functions. cd ../ITK; clang-tidy -p ITK-clangtidy $find Modules/[A-J]* -name *.cxx |fgrep -v ThirdParty) -checks=-*,modernize-use-override -header-filter=.* -fix clang-tidy -p ITK-clangtidy $(find Modules/[K-Z]* -name *.cxx |fgrep -v ThirdParty) -checks=-*,modernize-use-override -header-filter=.* -fix https://stackoverflow.com/questions/39932391/virtual-override-or-both-c When you override a function you don't technically need to write either virtual or override. The original base class declaration needs the keyword virtual to mark it as virtual. In the derived class the function is virtual by way of having the ¹same type as the base class function. However, an override can help avoid bugs by producing a compilation error when the intended override isn't technically an override. E.g. that the function type isn't exactly like the base class function. Or that a maintenance of the base class changes that function's type, e.g. adding a defaulted argument. In the same way, a virtual keyword in the derived class can make such a bug more subtle, by ensuring that the function is still is virtual in further derived classes. So the general advice is, virtual for the base class function declaration. This is technically necessary. Use override (only) for a derived class' override. This helps with maintenance.
1 parent b16d018 commit 6d8d304

6 files changed

+20
-20
lines changed

include/itkArrivalFunctionToPathFilter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ArrivalFunctionToPathCommand : public itk::Command
7979

8080
protected:
8181
ArrivalFunctionToPathCommand(){}
82-
~ArrivalFunctionToPathCommand(){}
82+
~ArrivalFunctionToPathCommand() ITK_OVERRIDE{}
8383

8484
private:
8585
ITK_DISALLOW_COPY_AND_ASSIGN(ArrivalFunctionToPathCommand);
@@ -212,8 +212,8 @@ class ITK_EXPORT ArrivalFunctionToPathFilter :
212212

213213
protected:
214214
ArrivalFunctionToPathFilter();
215-
~ArrivalFunctionToPathFilter();
216-
virtual void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
215+
~ArrivalFunctionToPathFilter() ITK_OVERRIDE;
216+
void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
217217

218218
/** Override since the filter needs all the data for the algorithm */
219219
void GenerateInputRequestedRegion() ITK_OVERRIDE;

include/itkIterateNeighborhoodOptimizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class MinimalPathExtraction_EXPORT IterateNeighborhoodOptimizer :
104104

105105
protected:
106106
IterateNeighborhoodOptimizer();
107-
virtual ~IterateNeighborhoodOptimizer() {};
107+
~IterateNeighborhoodOptimizer() ITK_OVERRIDE {};
108108
void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
109109

110110
private:

include/itkPhysicalCentralDifferenceImageFunction.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ITK_EXPORT PhysicalCentralDifferenceImageFunction :
8989
* \warning this method caches BufferedRegion information.
9090
* If the BufferedRegion has changed, user must call
9191
* SetInputImage again to update cached values. */
92-
virtual void SetInputImage( const InputImageType * ptr ) ITK_OVERRIDE
92+
void SetInputImage( const InputImageType * ptr ) ITK_OVERRIDE
9393
{
9494
this->Superclass::SetInputImage( ptr );
9595
if ( m_Interpolator.IsNotNull() )
@@ -103,7 +103,7 @@ class ITK_EXPORT PhysicalCentralDifferenceImageFunction :
103103
* No bounds checking is done. The point is assume to lie within the
104104
* image buffer. ImageFunction::IsInsideBuffer() can be used to check
105105
* bounds before calling this method. */
106-
virtual OutputType EvaluateAtIndex( const IndexType& index ) const ITK_OVERRIDE
106+
OutputType EvaluateAtIndex( const IndexType& index ) const ITK_OVERRIDE
107107
{
108108
PointType point;
109109
m_Interpolator->GetInputImage()->TransformIndexToPhysicalPoint( index, point );
@@ -116,7 +116,7 @@ class ITK_EXPORT PhysicalCentralDifferenceImageFunction :
116116
* No bounds checking is done. The point is assume to lie within the
117117
* image buffer. ImageFunction::IsInsideBuffer() can be used to check
118118
* bounds before calling this method. */
119-
virtual OutputType EvaluateAtContinuousIndex(
119+
OutputType EvaluateAtContinuousIndex(
120120
const ContinuousIndexType& cindex ) const ITK_OVERRIDE
121121
{
122122
PointType point;
@@ -130,11 +130,11 @@ class ITK_EXPORT PhysicalCentralDifferenceImageFunction :
130130
* No bounds checking is done. The point is assume to lie within the
131131
* image buffer. ImageFunction::IsInsideBuffer() can be used to check
132132
* bounds before calling this method. */
133-
virtual OutputType Evaluate( const PointType& point ) const ITK_OVERRIDE;
133+
OutputType Evaluate( const PointType& point ) const ITK_OVERRIDE;
134134

135135
protected:
136136
PhysicalCentralDifferenceImageFunction();
137-
~PhysicalCentralDifferenceImageFunction(){};
137+
~PhysicalCentralDifferenceImageFunction() ITK_OVERRIDE{};
138138
void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
139139

140140
private:

include/itkSingleImageCostFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ class ITK_EXPORT SingleImageCostFunction :
121121

122122
/** This method returns the value of the cost function corresponding
123123
* to the specified parameters. */
124-
virtual MeasureType GetValue( const ParametersType & parameters ) const ITK_OVERRIDE;
124+
MeasureType GetValue( const ParametersType & parameters ) const ITK_OVERRIDE;
125125

126126
/** This method returns the derivative of the cost function corresponding
127127
* to the specified parameters. */
128-
virtual void GetDerivative( const ParametersType & parameters,
128+
void GetDerivative( const ParametersType & parameters,
129129
DerivativeType & derivative ) const ITK_OVERRIDE;
130130

131131
// Set these depending on whether you will be minimizing or maximizing.
@@ -142,7 +142,7 @@ class ITK_EXPORT SingleImageCostFunction :
142142

143143
protected:
144144
SingleImageCostFunction();
145-
virtual ~SingleImageCostFunction() {}
145+
~SingleImageCostFunction() ITK_OVERRIDE {}
146146
void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
147147

148148
private:

include/itkSpeedFunctionPathInformation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ class SpeedFunctionPathInformation :
119119

120120
protected:
121121
SpeedFunctionPathInformation( );
122-
virtual ~SpeedFunctionPathInformation( );
123-
virtual void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
122+
~SpeedFunctionPathInformation( ) ITK_OVERRIDE;
123+
void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
124124

125125
std::vector< PointsContainerType > m_Information;
126126
SizeValueType m_Front;

include/itkSpeedFunctionToPathFilter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,27 @@ class ITK_EXPORT SpeedFunctionToPathFilter :
147147
}
148148

149149
/** Handle optimizer iteration events. */
150-
virtual void Execute( const itk::Object * object, const itk::EventObject & event ) ITK_OVERRIDE;
150+
void Execute( const itk::Object * object, const itk::EventObject & event ) ITK_OVERRIDE;
151151

152152
/** access the arrival image for debugging purposes */
153153
itkGetConstMacro( CurrentArrivalFunction, InputImagePointer );
154154

155155
protected:
156156
SpeedFunctionToPathFilter( );
157-
~SpeedFunctionToPathFilter( );
158-
virtual void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
157+
~SpeedFunctionToPathFilter( ) ITK_OVERRIDE;
158+
void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
159159

160160
/** Implemention of algorithm. */
161161
void GenerateData( void ) ITK_OVERRIDE;
162162

163163
/** Get the number of paths which the user has instructed to extracted. */
164-
virtual unsigned int GetNumberOfPathsToExtract( ) const ITK_OVERRIDE;
164+
unsigned int GetNumberOfPathsToExtract( ) const ITK_OVERRIDE;
165165

166166
/** Compute the arrival function from which to extract the path. */
167-
virtual InputImageType * ComputeArrivalFunction( ) ITK_OVERRIDE;
167+
InputImageType * ComputeArrivalFunction( ) ITK_OVERRIDE;
168168

169169
/** Override handling of optimizer iteration events to accomodate way points. */
170-
virtual const PointsContainerType & GetNextEndPoint( ) ITK_OVERRIDE;
170+
const PointsContainerType & GetNextEndPoint( ) ITK_OVERRIDE;
171171

172172
std::vector< typename PathInformationType::Pointer > m_Information;
173173
InputImagePointer m_CurrentArrivalFunction;

0 commit comments

Comments
 (0)