Pete Becker
10/9/2008 5:40:00 PM
On 2008-10-09 13:57:15 -0400, "Jim Langston" <tazmaster@rocketmail.com> said:
> "asm23" <asmwarrior@gmail.com> wrote in message news:gclann$tsh$1@aioe.org...
>> Hi, I'm using Intel C++ compiler 9 to compiler a project. But, there
>> are a lot of warning saying like "virtual function override
>> intended....". I searched old messages in Google groups, someone
>> already talk about this issue. But I still confused..
>>
>> This is the simple test code I copied from these messages
>> ////////////////////////////////////////////////////////////////////
>> class Base {
>> virtual void foo(); //*position A*
>> };
>>
>>
>> class Derived1 : Base {
>> virtual void foo(int); //*position B*
>> };
>>
>>
>> class Derived2 : Derived1 {
>> void foo(int); //*position C*
>> };
>> ////////////////////////////////////////////////////////////////////
>>
>> The compiler will report two warnings:
>>
>> Warning one:
>>
>> warning #1125: function "Base::foo()" is hidden by "Derived1::foo" --
>> virtual function override intended?
>>
>> Warning Two:
>>
>> warning #1125: function "Base::foo()" is hidden by "Derived2::foo" --
>> virtual function override intended?
>>
>> In my opinion, *overriding* is only occurred between two functions
>> which have the same signature and parameter list. It seems that the
>> function prototype are different between class Base and class Derived1.
>>
>> I will be very appreciated if you can give me some explanation. Thank
>> you for reading my post.
>
> Unfortunately what you opionion is and what the facts are don't happen
> to mesh on this.
No, it's correct: a function in a derived class overrides a virtual
function in a base class with the same name and signature. A function
in a derived class with the same name as a function in a base class but
a different signature hides the one in the base class.
> If you have the same function name, reguardless of signature, you
> will hide a base function by the derived function. The best work
> around is, name your function something different in your derived.
> Unless you actually intended polymorphism, then fix the signatures and
> use the virtual keyword in the base.
Agreed: hiding a function often reflects a design error.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)