In article <Yi93f.417919$5N3.307781@bgtnsc05-news.ops.worldnet.att.net>,
Howard <alicebt@hotmail.com> wrote:[color=blue]
>"Greg Comeau" <comeau@panix.com> wrote in message
>news:dihaab$fhv$1@panix2.panix.com...[color=green]
>> In article <weV2f.413332$5N3.277561@bgtnsc05-news.ops.worldnet.att.net>,
>> Howard <alicebt@hotmail.com> wrote:[color=darkred]
>>>
>>>"Greg Comeau" <comeau@panix.com> wrote in message
>>>news:dih6k8$332$1@panix2.panix.com...
>>>> In article <59T2f.412714$5N3.216579@bgtnsc05-news.ops.worldnet.att.net>,
>>>> Howard <alicebt@hotmail.com> wrote:
>>>>>As a standard practice, though, I always repeat [virtual] in derived
>>>>>classes, just so that I KNOW it's a virtual method, and don't have to
>>>>>look
>>>>>back through my base classes to see if it's declared virtual somewhere.
>>>>>(Besides, I usually copy & paste the function declarations into my
>>>>>derived
>>>>>class anyway, so the virtual keyword gets copied right along with the
>>>>>rest
>>>>>of the function declaration.)
>>>>
>>>> I buy this up to a point, however, such a dependency can be
>>>> (1) a false sense of security and (2) someitme outright wrong
>>>> at least as I understand what you wrote.
>>>> --
>>>
>>>I don't get you. What's wrong with my approach? Where might it cause me
>>>trouble to always include the virtual keyword for methods in derived
>>>classes
>>>when the virtual keyword is specified for the base class function(s) being
>>>overridden?
>>>
>>>The only "false sense of security" might be if I were to assume that any
>>>function which does not have the virtual keyword must NOT be virtual. I
>>>never implied I would do that. I said I would know it WAS virtual by its
>>>presence, not the other way around. If I do NOT see the virtual keyword,
>>>then I have to look back through any base classes to see if perhaps it IS
>>>actually virtual. (Thus, always repeating the virtual keyword for
>>>overriding methods saves me the time I would otherwise need to look it
>>>up.)[/color]
>>
>> Somebody (not necessarily you) may for instance have:
>>
>> struct xyz {
>> void foo();
>> };
>>
>> struct abc : xyz {
>> virtual void foo();
>> };
>>
>> Seeing foo is virtual in abc says nothing of it in xyz.
>> --[/color]
>
>I think my compiler issues a warning if I do that, saying that a virtual
>function is hiding a non-virtual function in the base class.
>
>In any case, I take it your point is that if I see the virtual keyword in
>abc above, then I still have to be careful about any assumptions I make
>about whether it's virtual in the base class or not. Point taken.[/color]
My point is to not make any assumptions, but indeed instead to do
the careful inspection, etc.
[color=blue]
>I still
>think it's good practice, even if it's not a foolproof guarantee. (There
>are always bigger fools...)[/color]
Not only is it not foolproof, it's not even expert proof.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==>
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?