Re: Operators Inherited?
- From: "Shak" <me@xxxxxxxxxxx>
- Date: Thu, 3 Aug 2006 09:33:34 +0100
"Barry Kelly" <barry.j.kelly@xxxxxxxxx> wrote in message
news:gis1d2dvkvl6gosfc3ot04ik70fve4urrn@xxxxxxxxxx
"Shak" <me@xxxxxxxxxxx> wrote:
I was led to believe that static methods were not inherited by their
subclasses (and since that makes sense, rightly so).
They can't be overridden, so they're not inherited in the same way as
virtual methods are, but the whole namespace of the ancestor type is
merged into the descendant type, so there is a kind of inheritance of
scope.
Is that just the case for operators?
However, a subclass I've written is using it's (abstract) superclass's
operators. How can that be when operators are always static?
When you use an operator on two custom types, the compiler examines both
types' scopes, looking for operator overload definitions. So, if you've
got two types, Foo and Bar, with values foo and bar:
foo Op bar
... it'll look in the namespaces of both Foo and Bar for static methods
called op_Op (where 'Op' is Add, Subtract, etc.) for which there exist
overloads that can accept values of type (Foo, Bar). That 'accept'
includes polymorphism by way of inheritance, of course.
Again, is this just the case for operators?
Now, static methods don't get inherited in the sense of a virtual
instance method - but because the whole namespace is inherited, all the
public static methods that are visible in the ancestor are also visible
in the descendant. Thus, the ancestor's operators also work on its
descendants.
But if that's so, why can't you call a superclass's static method from its
subclass (like I try to do in my other post)?
Shak
.
- Follow-Ups:
- Re: Operators Inherited?
- From: Shak
- Re: Operators Inherited?
- References:
- Operators Inherited?
- From: Shak
- Re: Operators Inherited?
- From: Barry Kelly
- Operators Inherited?
- Prev by Date: Re: Operators Inherited?
- Next by Date: Re: Operators Inherited?
- Previous by thread: Re: Operators Inherited?
- Next by thread: Re: Operators Inherited?
- Index(es):
Relevant Pages
|