Skip to content

Name-hiding issues of overriding member fcts in derived classes

Michel Rasquin requested to merge fix-name-hiding into master

This branch includes commits which fix several occurrences of the same issue related to name-hiding of overriding member functions in derived classes. These overriding member functions in derived classes hide partially some overloaded (virtual) members functions of the corresponding base class, which can lead to vicious bugs in the code. These issues can be highlighted by the gcc compiler with the -Woverloaded-virtual option. Although none of the warnings thrown by the compiler with this option appeared to be actual bugs, they still open the door to weird behavior in the future so that it is safer to fix them. These warnings were highlighted by the Kitware people during the integration of a gmsh reader which relies on the gmsh lib in the paraview sources.

Three strategies have been implemented to fix these name-hiding issues:

  1. In most cases, the following instruction is added in the derived classes where member functions "function_name" were hidden from their virtual counterpart in the base class:
    Using baseClass::function_name;

See for instance http://www.programmerinterview.com/index.php/c-cplusplus/c-name-hiding/ for more info. Note that the older way to avoid this issue was to repeat the definition of the virtual overloaded function prototypes in the derived classes. the "Using approach is however cleaner and more complete.

  1. In Geo/GVertex.cpp, the hidden function void GVertex::getNumMeshElements(unsigned *const c) const has been simply implemented in the GVertex derived class (the base class of GVertex is GEntity).

  2. In Mesh/Field.h, the function

virtual void operator()(double x, double y, double z, SVector3& v1, SVector3& v2,
                          SVector3& v3,GEntity* ge=0){}

which was marked as temporary in the source code of the Field base class has been removed so that it could not be hidden to the Field derived classes any more.

Merge request reports