Diagnostic 1125: entity-kind "entity" is hidden by "entity" -- virtual function override intended?

Submit New Article

Last Modified On :   December 14, 2008 3:33 PM PST
Rate
 


Cause:

Compiler encounters code in which one entity is hidden by another, this results in being no use of first entity.

Examples:

  • When a virtual base class function that is an entity gets overloaded (Out of scope) in derived class. i.e. Derived class implements the base virtual function that is another entity with same name and different parameters.

The following sample generates Warning 1125 :

class Base{
public :
	virtual void foo (float f){ }
}; 

class Derived : public Base {
public :
	void foo (char c) { }
};

void foobar ()
{
	Derived d;
	char c1 = 'c';
	float f1 = 46.68;
	d.foo (c1); // Derived is called
	d.foo (f1); // Derived is called even though argument is float. Base class function gets hidden
}


>> icl /c t.cpp
Intel(R) C++ Compiler Professional for applications running on IA-32, Version 1
1.0 Build 20080930 Package ID: w_cproc_p_11.0.061
Copyright (C) 1985-2008 Intel Corporation. All rights reserved. t.cpp
t.cpp(8): warning #1125: function "Base::foo(float)" is hidden by "Derived::foo"
-- virtual function override intended?
void foo (char c) { }
^

Default type of this diagnostic is Warning

Solution:

Unhide the base function by:

  1. Not to overload base class function in derived class
  2. "using" keyword: Declare the base function again in derived with using keyword as shown in the following code:

The "class Derived" should be:

class Derived : public Base {
public :
	using Base::foo;
	void foo (char c) { }
};
 




This article applies to: Intel® C++ Compiler for Linux* Knowledge Base,   Intel® C++ Compiler for Mac OS X* Knowledge Base,   Intel® C++ Compiler for Windows* Knowledge Base,   Intel® Parallel Composer Knowledge Base