From f24266586789c763d11f9c6e62397a90afb1b76a Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sat, 16 Dec 2017 19:16:56 -0600 Subject: [PATCH] ENH: ITKv5 override consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- include/itkAdditiveGaussianNoiseMeshFilter.h | 2 +- include/itkAdditiveGaussianNoiseQuadEdgeMeshFilter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/itkAdditiveGaussianNoiseMeshFilter.h b/include/itkAdditiveGaussianNoiseMeshFilter.h index 1538b50..fa82732 100644 --- a/include/itkAdditiveGaussianNoiseMeshFilter.h +++ b/include/itkAdditiveGaussianNoiseMeshFilter.h @@ -79,7 +79,7 @@ public MeshToMeshFilter< TInput, TOutput > protected: AdditiveGaussianNoiseMeshFilter(); - ~AdditiveGaussianNoiseMeshFilter() override{} + ~AdditiveGaussianNoiseMeshFilter() ITK_OVERRIDE{} void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; diff --git a/include/itkAdditiveGaussianNoiseQuadEdgeMeshFilter.h b/include/itkAdditiveGaussianNoiseQuadEdgeMeshFilter.h index f310e8c..77db8ee 100644 --- a/include/itkAdditiveGaussianNoiseQuadEdgeMeshFilter.h +++ b/include/itkAdditiveGaussianNoiseQuadEdgeMeshFilter.h @@ -72,7 +72,7 @@ class AdditiveGaussianNoiseQuadEdgeMeshFilter: protected: AdditiveGaussianNoiseQuadEdgeMeshFilter(); - ~AdditiveGaussianNoiseQuadEdgeMeshFilter() override{} + ~AdditiveGaussianNoiseQuadEdgeMeshFilter() ITK_OVERRIDE{} void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;