By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

Abstract members in non-abstract classes?

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 Veeneman" <da****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... 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

Nov 15 '05 #2

P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.