Re: Operators Inherited?

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



"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


.



Relevant Pages

  • Re: Class inheritance
    ... > class Foo ... > class Bar ... > function FooBar() ... > than inheritance, but it seems to me the effect is close. ...
    (comp.lang.php)
  • Re: Operators Inherited?
    ... got two types, Foo and Bar, with values foo and bar: ... includes polymorphism by way of inheritance, ... static methods don't get inherited in the sense of a virtual ...
    (microsoft.public.dotnet.general)
  • Re: Disadvantages of Inheritance, Polymorphism and Encapsulation
    ... > polymorphism, inheritance and encapsulation. ... If object Foo ... Bar, in return, should not surprise Foo. ... When two classes associate by inheritance, ...
    (comp.object)
  • Re: explicitly invoking a superclass method
    ... > void foo() ... > to bar() - I'm just a bit concerned that maybe the author was trying to ... Foo ... inheritance. ...
    (comp.lang.java.programmer)
  • Re: Design choice: subclassing or "supplementing"
    ... > I have this class from CPAN (let's call it, creatively enough, Foo) ... bar) that I think could be significantly enhanced. ... Overriding base class methods is more than just replacement. ... need to do via inheritance, ...
    (comp.lang.perl.misc)