473,757 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9605
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******** ********@TK2MSF TNGP12.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
4907
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 the middle of developing, in which users have the right to view some data and edit some data in a set of tables. The data is pulled up in a set of views (using SQL Server 7 with an Access 2000 front-end). Depending on an initial selection that...
3
3612
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 non-standard C++ or if the problem lies elsewhere. To summarize static const class members are not being accessed properly when accessed from a DLL by another external object file (not within the DLL). It only occurs when the static const...
6
2471
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 type of its own class. Non-static data members can not be declared as type of its own class (excluding pointers and references).
43
2141
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 Static member 'ClassInCS.ABC.MyInt' cannot be accessed with an instance reference; qualify it with a type name
3
9758
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 mauzi
2
2981
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 help. I've read some books, but no book focuses on this. Don't you think it is a very important thing of C++ programming language? So your knowledge is of great benefit to others, especially me. 1. Which (How many) members will be created...
3
1688
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 initiated in the header). Does anyone no the reason? Thanks alot,
10
2096
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
2047
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 holding to the theory? Pls explain. Here is an example: namespace StaticNonStaticMembers { class Program {
1
1836
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" defaultUrl="/Members/Welcome.aspx" protection="All" requireSSL="false" path="/" /> </authentication> Now I would like to restrict certain subfolders within /Members by Role. I have the following roles for testing:
0
9487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9735
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7285
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.