Abstract members in non-abstract classes?

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
 
J

Jay B. Harlow [MVP - Outlook]

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
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top