Abstract members in non-abstract classes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Veeneman

    Abstract members in non-abstract classes?

    Is is legal to declare abstract members in non-abstract classes? How about
    non-abstract members in abstract classes?

    I am writing a base class with three derived classes. The base class will
    define the behavior for most, but not all of its members. The derived
    classes will define the behavior for the remaining members (the undefined
    members).

    I'd like to force the derived classes to implement the undefined members in
    the base class. I assumed that I could simply declare those members as
    abstract. But I'm getting a compiler error that says I can't declare
    abstract members in a non-abstract class. If I declare the base class as an
    abstract class, the compiler won't let me define the behavior of the
    concrete members in the base class.

    This looks like an all-or-nothing proposition to me. If I declare a class as
    abstract, all its members must be abstract, and if I don't declare the class
    as abstract, it can't have any abstract members. Is that correct? If so,
    what's the rationale? It seems awfully inflexible, so I figure there must be
    a good reason for it. Thanks

    --
    Dave Veeneman
    Chicago


  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: Abstract members in non-abstract classes?

    Dave,
    Abstract members can only be in abstract classes!

    However non-abstract members can also be abstract classes!
    [color=blue]
    > If I declare the base class as an
    > abstract class, the compiler won't let me define the behavior of the
    > concrete members in the base class.[/color]
    Can you give an example of what you tried?

    Hope this helps
    Jay

    "Dave Veeneman" <davidv@nospam. com> wrote in message
    news:%23yjvwDjq DHA.1708@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Is is legal to declare abstract members in non-abstract classes? How about
    > non-abstract members in abstract classes?
    >
    > I am writing a base class with three derived classes. The base class will
    > define the behavior for most, but not all of its members. The derived
    > classes will define the behavior for the remaining members (the undefined
    > members).
    >
    > I'd like to force the derived classes to implement the undefined members[/color]
    in[color=blue]
    > the base class. I assumed that I could simply declare those members as
    > abstract. But I'm getting a compiler error that says I can't declare
    > abstract members in a non-abstract class. If I declare the base class as[/color]
    an[color=blue]
    > abstract class, the compiler won't let me define the behavior of the
    > concrete members in the base class.
    >
    > This looks like an all-or-nothing proposition to me. If I declare a class[/color]
    as[color=blue]
    > abstract, all its members must be abstract, and if I don't declare the[/color]
    class[color=blue]
    > as abstract, it can't have any abstract members. Is that correct? If so,
    > what's the rationale? It seems awfully inflexible, so I figure there must[/color]
    be[color=blue]
    > a good reason for it. Thanks
    >
    > --
    > Dave Veeneman
    > Chicago
    >
    >[/color]


    Comment

    • Mattias Sjögren

      #3
      Re: Abstract members in non-abstract classes?

      Dave,
      [color=blue]
      >Is is legal to declare abstract members in non-abstract classes?[/color]

      No.

      [color=blue]
      >How about non-abstract members in abstract classes?[/color]

      Yes

      [color=blue]
      >If I declare the base class as an
      >abstract class, the compiler won't let me define the behavior of the
      >concrete members in the base class.[/color]

      Really? What does your code look like?



      Mattias

      --
      Mattias Sjögren [MVP] mattias @ mvps.org

      Please reply only to the newsgroup.

      Comment

      Working...