Abstract members in non-abstract classes?

  • Thread starter Thread starter Dave Veeneman
  • Start date Start date
D

Dave Veeneman

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,
Abstract members can only be in abstract classes!

However non-abstract members can also be abstract classes!
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.
Can you give an example of what you tried?

Hope this helps
Jay
 
Dave,
Is is legal to declare abstract members in non-abstract classes?
No.


How about non-abstract members in abstract classes?
Yes


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.

Really? What does your code look like?



Mattias
 
Back
Top