Re: What can I store in LPARAM
- From: "GT" <ContactGT_remove_@xxxxxxxxxxx>
- Date: Thu, 18 Jan 2007 15:19:21 -0000
"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
.
- Follow-Ups:
- Re: What can I store in LPARAM
- From: David Wilkinson
- Re: What can I store in LPARAM
- References:
- What can I store in LPARAM
- From: GT
- Re: What can I store in LPARAM
- From: AliR \(VC++ MVP\)
- Re: What can I store in LPARAM
- From: GT
- Re: What can I store in LPARAM
- From: AliR \(VC++ MVP\)
- Re: What can I store in LPARAM
- From: Tom Serface
- Re: What can I store in LPARAM
- From: AliR \(VC++ MVP\)
- Re: What can I store in LPARAM
- From: Tom Serface
- Re: What can I store in LPARAM
- From: AliR \(VC++ MVP\)
- Re: What can I store in LPARAM
- From: GT
- Re: What can I store in LPARAM
- From: David Wilkinson
- Re: What can I store in LPARAM
- From: GT
- Re: What can I store in LPARAM
- From: David Wilkinson
- Re: What can I store in LPARAM
- From: GT
- Re: What can I store in LPARAM
- From: David Wilkinson
- What can I store in LPARAM
- Prev by Date: Re: Which function should I use?Thanks!
- Next by Date: Re: how to import an existing dialog box from one application to another application in MFC
- Previous by thread: Re: What can I store in LPARAM
- Next by thread: Re: What can I store in LPARAM
- Index(es):
Relevant Pages
|