473,800 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Superclass and Subclasses

I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..

Sep 1 '07 #1
14 4083
On 2007-09-01 12:22, Marko wrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
I don't see the problem, if the And class is a subclass of Element that
should work. Please explain your problem in more detail.

--
Erik Wikström
Sep 1 '07 #2
On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..
Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?

-N
Sep 1 '07 #3
On Sep 1, 12:38 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..

Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?

-N
OK, it just start working.
I don't know what happened. I probably overlooked something obvious.

But now, I have new problem, and this time I'm not even sure that this
thing
can be done the way I am trying to do it.

I have to make a dynamic array of Element type, so it can contain any
of
the derived class objects.

Sep 1 '07 #4
On 2007-09-01 17:07, Marko wrote:
On Sep 1, 12:38 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
>On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..

Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?

-N

OK, it just start working.
I don't know what happened. I probably overlooked something obvious.

But now, I have new problem, and this time I'm not even sure that this
thing can be done the way I am trying to do it.

I have to make a dynamic array of Element type, so it can contain any
of the derived class objects.
Can't do that (at least not easily), you have to make an array (vector)
of pointers to Element.

--
Erik Wikström
Sep 1 '07 #5
Marko wrote:
On Sep 1, 12:38 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
>On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..

Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?

-N

OK, it just start working.
I don't know what happened. I probably overlooked something obvious.

But now, I have new problem, and this time I'm not even sure that this
thing
can be done the way I am trying to do it.

I have to make a dynamic array of Element type, so it can contain any
of the derived class objects.
You cannot make an array of that kind. But you can make an array of pointers
to Element, and those can point to derived class objects.

Sep 1 '07 #6
On Sep 1, 5:34 pm, Rolf Magnus <ramag...@t-online.dewrote:
Marko wrote:
On Sep 1, 12:38 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..
Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?
-N
OK, it just start working.
I don't know what happened. I probably overlooked something obvious.
But now, I have new problem, and this time I'm not even sure that this
thing
can be done the way I am trying to do it.
I have to make a dynamic array of Element type, so it can contain any
of the derived class objects.

You cannot make an array of that kind. But you can make an array of pointers
to Element, and those can point to derived class objects.
You mean somthing like Element** myArray;?

Sep 1 '07 #7
On Sep 1, 5:34 pm, Rolf Magnus <ramag...@t-online.dewrote:
Marko wrote:
On Sep 1, 12:38 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..
Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?
-N
OK, it just start working.
I don't know what happened. I probably overlooked something obvious.
But now, I have new problem, and this time I'm not even sure that this
thing
can be done the way I am trying to do it.
I have to make a dynamic array of Element type, so it can contain any
of the derived class objects.

You cannot make an array of that kind. But you can make an array of pointers
to Element, and those can point to derived class objects.
Could type casting do some good.

Sep 1 '07 #8
On 2007-09-01 17:44, Marko wrote:
On Sep 1, 5:34 pm, Rolf Magnus <ramag...@t-online.dewrote:
>Marko wrote:
On Sep 1, 12:38 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..
>Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?
>-N
OK, it just start working.
I don't know what happened. I probably overlooked something obvious.
But now, I have new problem, and this time I'm not even sure that this
thing
can be done the way I am trying to do it.
I have to make a dynamic array of Element type, so it can contain any
of the derived class objects.

You cannot make an array of that kind. But you can make an array of pointers
to Element, and those can point to derived class objects.

Could type casting do some good.
No, the problem is that if you try to store an object of type And in an
array of type Element the And will be sliced (everything that differ
from Element will be discarded) and only the stuff that it has in common
with Element is stored. In other words it will no longer be an object of
type And, but of Element.

--
Erik Wikström
Sep 1 '07 #9
On 2007-09-01 17:42, Marko wrote:
On Sep 1, 5:34 pm, Rolf Magnus <ramag...@t-online.dewrote:
>Marko wrote:
On Sep 1, 12:38 pm, Neelesh Bodas <neelesh.bo...@ gmail.comwrote:
On Sep 1, 3:22 pm, Marko <cb...@outgun.c omwrote:
I have abstract superclass named Element, and several subclasses
derived from it: And, Or, Nand, Nor...
I have method which has to take 2 subclasses of element as its
parameters types.
Can't use void myFunction(Elem ent& e1,Element& e2); prototype because
I am trying to pass it objects of class And or any other subclass.
Need help..
>Why can't you use void myFunction(Elem ent& e1,Element& e2); ? If
'And', 'Or' etc are publicly derived from Element then 'And' is-an
'Element' and hence it can be passed to a function which exepcts an
Element&. What is the exact issue?
>-N
OK, it just start working.
I don't know what happened. I probably overlooked something obvious.
But now, I have new problem, and this time I'm not even sure that this
thing
can be done the way I am trying to do it.
I have to make a dynamic array of Element type, so it can contain any
of the derived class objects.

You cannot make an array of that kind. But you can make an array of pointers
to Element, and those can point to derived class objects.

You mean somthing like Element** myArray;?
Yes, or Element* myArray[size], or even better std::vector<Ele ment*>.

--
Erik Wikström
Sep 1 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2900
by: Thomas Philips | last post by:
I'm teaching myself programming using Python, and have a question about subclasses. My game has two classes, Player and Alien, with identical functions, and I want to make Player a base class and Alien a derived class. The two classes are described below class Player(object): #Class attributes for class Player threshold = 50 n=0 #n is the number of players
0
1308
by: Vera | last post by:
Hi, I have a very annoying problem, with which I NEED HELP DESPERATELY!! It smells like a bug to me, but I'm not sure. SITUATION This description is a very much simplified version of the real situation. I have the following class structure: ASSEMBLY ATools
8
3006
by: Marco | last post by:
Hi all, I have a base class and some subclasses; I need to define an array of objects from these various subclasses. What I have is something like: { //I have a base class, something like: class CPeople {
2
1188
by: rh0dium | last post by:
Hi all, Still a newbie but making some headway. So I have a file structure like this.. top/ --modules/ ----metrics.py --metrix/ ----uptime.py
2
3037
by: stephane | last post by:
Hi all, What I am trying to achieve is an 'inherits' method similar to Douglas Crockford's (http://www.crockford.com/javascript/inheritance.html) but that can enable access to the superclass' priviledged methods also. Do you know if this is possible ? In the following example, I create an ObjectA (variable a), an ObjectB which inherits ObjectA (variable b) and an ObjectC which inherits ObjectA (variable c1). The 'toString ()' method...
2
4420
by: MR | last post by:
I'm hoping that someone here will be able to direct me to some litrature on how to get a list of a classes subclasses. I.e. need the inherited class to know about subclasses that are inherited form it. I guess that I'll have to use reflection but I can't find any examples on MSDN. Thanks in advance, Mark
3
1837
by: tac-tics | last post by:
I have a program which has a GUI front-end which that runs a separate thread to handle all the important stuff. However, if there is a problem with the important stuff, I want the GUI to raise a MessageBox alert to indicate this. For exceptions, I can simply use a catch-all except statement like: try: ... except Exception, error:
1
2865
by: shivapadma | last post by:
1..In java we can refer superclass constructor by super()keyword,but Where as in c++ how can we refer to that???. In java the following code is used for referring superclass constructor.. class cal1 { private int a,b,c; public cal1(int i,int j) { a=i;
2
2381
by: Mark Brading | last post by:
Hi all, I am trying to declare a Map object with an abstract superclass (TableFields_v2) object as follows:- private Map<Integer, TableFields_v2> elementList; When I come to create the object element for the Map I want to be able to use a subclass of the superclass for the object; for example:- this.elementList = new HashMap<Integer, TableFields_v2_Year>(); Where TableFields_v2_Year is a subclass of TableFields_v2 However, Java won't...
0
9691
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
9551
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
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9090
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...
0
6813
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
5471
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...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.