473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
Nov 15 '05 #1
2 9580
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Oren | last post by:
Hi, Is there any way that calls to sp_addrolemember and sp_droprolemember can be enabled for non database owners and non sysadmin members? This would be very helpful for an application I'm in...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
6
by: lovecreatesbeauty | last post by:
Hello Experts, Why static data members can be declared as the type of class which it belongs to? Inside a class, non-static data members such as pointers and references can be declared as...
43
by: Mark | last post by:
Hello Friends Please check the code below. One in C# and other in VB .Net In C# I am not able to access a static property by an instance variable, but in VB I can do it easily. The Error is ...
3
by: Mauzi | last post by:
hi, this may sound odd and noob like, but what is the 'big' difference between static and non-static funcitons ? is there any performace differnce? what is the best way to use them ? thnx ...
2
by: lovecreatesbeauty | last post by:
I'm disturbed on this question on a long time. I think if I finally get understand it with your kind help, I will get close to a excellent C++ programmer. And I only can rely on your expertise and...
3
by: Bari | last post by:
Hi all, I just wanted to know if I can ininialize data members in the header. The compiler (gcc 2.96) returns an error. The data members are not const (I know that const members can't be...
10
by: asdf | last post by:
data members defined after a private label are not accessible to code that uses the class. So, can I define the private data members as const?
8
by: Rajesh | last post by:
Based on my understanding static members do not have access to non- static members. In the below example static method 'name' accessing non-static method creating reference. Seems to me it is not...
1
by: djnokturnal | last post by:
Hey guys/gals, I have successfully implemented forms authentication on my site: <authentication mode="Forms"> <forms loginUrl="/Members/Login.aspx" timeout="20"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.