Re: What can I store in LPARAM

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:uN%23enxwOHHA.1248@xxxxxxxxxxxxxxxxxxxxxxx
GT wrote:

I believe the word "override" is correct only for virtual functions. What
you are doing is redefining (hiding, shadowing).


Interesting:

I'm not saying you're wrong, but with my call back up to the base class,
I don't see a difference and therefore don't understand the point of the
'Virtual' keyword. If a base class defines an operation with public
visibility, then any subclasses automatically inherrit that method and
may choose to override it completely, or by adding code before or after
the original code. I have been coding in C++ for about 10 years and I am
not an expert, but it sounds like the 'virtual' keyword breaks the OO
convention, unless it is the C++ implementation of 'leaf', in which case
the compiler should not let me do what I have done above - it should
prevent my class from specifying a DeleteItem() operation - see my
comments below regarding leaf.


There is no need for your function to have the same name as the base
class DeleteItem, and some would say you should not use the same name.


With a different name, it wouldn't be an overridden method and would not
behave polymorphically. The point of keeping it the same name is so you
can write client code to take and handle objects of type CTreeCtrl, but
at runtime actually pass objects of various subclass types. They
automatically conform to the interface as CTreeCtrl, but may have
overriden methods, additional methods, additional attributes and
additional relationships.


See Scott Myers book "Effective C++", item 37 (in the second edition).
One argument Myers gives for not redefining non-virtual methods is that
it destroys the "is a" nature of public inheritance.


Does he give any arguments in favour of it, because like I said, in OO
the only way to prevent a method being overriden is to define it as
'leaf'. This means that a subclass can't change the method body behind
the operation. 'leaf' can also be applied to a class to prevent anyone
from inheriting from it. This can be useful for security purposes -
prevent someone subclassing a class and overriding the security
operations (such as password checking methods).

GT:

Your method does NOT work polymorphically, because it is not declared
virtual in the base class. But presumably you use a control variable of
type MyTreeClass, so you do not need the polymorphic behavior.

If you were to call DeleteItem() using a CTreeControl pointer to your
derived class object, you would not get your derived class behavior.

"Leaf" is not a C++ keyword. Is this Java terminology? (I don't know
Java). In C++ only methods declared virtual in the base class will show
polymorphic behavior.

David Wilkinson

'leaf' is a UML term, independant of language. In UML a method defined as a
'leaf' cannot be overridden in a subclass. In UML all methods can be
overridden in a subclass, unless you define them as 'leaf'. It would appear
in C++ that all methods cannot be overridden in a subclass unless you
specify virtual in the base class. The opposite way round, but achieving the
same result.

So surely, we should always use the Virtual keyword before operation names,
with only the occasional exception?

GT


.



Relevant Pages

  • Re: What can I store in LPARAM
    ... I'm not saying you're wrong, but with my call back up to the base class, I don't see a difference and therefore don't understand the point of the 'Virtual' keyword. ... If a base class defines an operation with public visibility, then any subclasses automatically inherrit that method and may choose to override it completely, or by adding code before or after the original code. ... I have been coding in C++ for about 10 years and I am not an expert, but it sounds like the 'virtual' keyword breaks the OO convention, unless it is the C++ implementation of 'leaf', in which case the compiler should not let me do what I have done above - it should prevent my class from specifying a DeleteItemoperation - see my comments below regarding leaf. ... But presumably you use a control variable of type MyTreeClass, so you do not need the polymorphic behavior. ...
    (microsoft.public.vc.mfc)
  • Re: Subclassing controls
    ... Suppose their is a property called Bold that I can't override. ... own base class version or will it see my new implementation of it? ... At any time, from within the definition of the subclass, you may ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: virtual and override methods
    ... If C didn't have an override, ... > inherits the virtual method from A? ... > make calls to overridden members in the base class by prefacing the ... > the other subclass uses this ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What can I store in LPARAM
    ... In OO terminology I have overriden the base class method, ... I believe the word "override" is correct only for virtual functions. ... unless it is the C++ implementation of 'leaf', ... means that a subclass can't change the method body behind the operation. ...
    (microsoft.public.vc.mfc)
  • Re: What can I store in LPARAM
    ... In UML all methods can be overridden in a subclass, unless you define them as 'leaf'. ... It would appear in C++ that all methods cannot be overridden in a subclass unless you specify virtual in the base class. ... In C++ any method can be redefined, but only virtual methods override. ...
    (microsoft.public.vc.mfc)