Skip to content

Commit 0e757b2

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 43ac1b4 commit 0e757b2

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

include/itkCoocurrenceTextureFeaturesImageFilter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class ITK_TEMPLATE_EXPORT CoocurrenceTextureFeaturesImageFilter
208208
typedef typename NeighborhoodIteratorType::NeighborIndexType NeighborIndexType;
209209

210210
CoocurrenceTextureFeaturesImageFilter();
211-
virtual ~CoocurrenceTextureFeaturesImageFilter() {}
211+
~CoocurrenceTextureFeaturesImageFilter() ITK_OVERRIDE {}
212212

213213
bool IsInsideNeighborhood(const OffsetType &iteratedOffset);
214214
void ComputeFeatures(const vnl_matrix<unsigned int> &hist, const unsigned int totalNumberOfFreq,
@@ -219,14 +219,14 @@ class ITK_TEMPLATE_EXPORT CoocurrenceTextureFeaturesImageFilter
219219
double & marginalMean,
220220
double & marginalDevSquared,
221221
double & pixelVariance);
222-
virtual void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
222+
void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
223223

224224
/** This method causes the filter to generate its output. */
225-
virtual void BeforeThreadedGenerateData() ITK_OVERRIDE;
226-
virtual void AfterThreadedGenerateData() ITK_OVERRIDE;
227-
virtual void ThreadedGenerateData(const OutputRegionType & outputRegionForThread,
225+
void BeforeThreadedGenerateData() ITK_OVERRIDE;
226+
void AfterThreadedGenerateData() ITK_OVERRIDE;
227+
void ThreadedGenerateData(const OutputRegionType & outputRegionForThread,
228228
ThreadIdType threadId) ITK_OVERRIDE;
229-
virtual void GenerateOutputInformation() ITK_OVERRIDE;
229+
void GenerateOutputInformation() ITK_OVERRIDE;
230230

231231
private:
232232
typename DigitizedImageType::Pointer m_DigitizedInputImage;

include/itkFirstOrderTextureFeaturesImageFilter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ITK_TEMPLATE_EXPORT FirstOrderTextureFeaturesImageFilter:
9393
{
9494
}
9595

96-
void GenerateOutputInformation()
96+
void GenerateOutputInformation() ITK_OVERRIDE
9797
{
9898
// this methods is overloaded so that if the output image is a
9999
// VectorImage then the correct number of components are set.
@@ -112,7 +112,7 @@ class ITK_TEMPLATE_EXPORT FirstOrderTextureFeaturesImageFilter:
112112
}
113113

114114

115-
~FirstOrderTextureFeaturesImageFilter() {}
115+
~FirstOrderTextureFeaturesImageFilter() ITK_OVERRIDE {}
116116
private:
117117
FirstOrderTextureFeaturesImageFilter(const Self &); //purposely not implemented
118118
void operator=(const Self &); //purposely not implemented

include/itkRunLengthTextureFeaturesImageFilter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter
232232
typedef typename NeighborhoodIteratorType::NeighborIndexType NeighborIndexType;
233233

234234
RunLengthTextureFeaturesImageFilter();
235-
virtual ~RunLengthTextureFeaturesImageFilter() {}
235+
~RunLengthTextureFeaturesImageFilter() ITK_OVERRIDE {}
236236

237237
void NormalizeOffsetDirection(OffsetType &offset);
238238
bool IsInsideNeighborhood(const OffsetType &iteratedOffset);
@@ -241,14 +241,14 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter
241241
const OffsetType &offset, const unsigned int &pixelDistance);
242242
void ComputeFeatures( vnl_matrix<unsigned int> &hist, const unsigned int &totalNumberOfRuns,
243243
typename TOutputImage::PixelType &outputPixel);
244-
virtual void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
244+
void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
245245

246246
/** This method causes the filter to generate its output. */
247-
virtual void BeforeThreadedGenerateData() ITK_OVERRIDE;
248-
virtual void AfterThreadedGenerateData() ITK_OVERRIDE;
249-
virtual void ThreadedGenerateData(const OutputRegionType & outputRegionForThread,
247+
void BeforeThreadedGenerateData() ITK_OVERRIDE;
248+
void AfterThreadedGenerateData() ITK_OVERRIDE;
249+
void ThreadedGenerateData(const OutputRegionType & outputRegionForThread,
250250
ThreadIdType threadId) ITK_OVERRIDE;
251-
virtual void GenerateOutputInformation() ITK_OVERRIDE;
251+
void GenerateOutputInformation() ITK_OVERRIDE;
252252

253253
private:
254254
typename DigitizedImageType::Pointer m_DigitizedInputImage;

0 commit comments

Comments
 (0)