473,498 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple inheritance

4 New Member
Hello,

I have an inheritance hierarchy like this:
Expand|Select|Wrap|Line Numbers
  1. class Person{
  2. ...
  3. }
  4.  
  5. class HandlerSubjects{
  6.          public:
  7.                    virtual void setSubject(string);
  8. .....
  9. }
  10.  
  11.  
  12. class Estudient: public Person,public HandlerSubjects{
  13.  
  14. ....
  15.  
  16. }
  17.  
in main I have:
Expand|Select|Wrap|Line Numbers
  1. Person* p;
  2. *p=new Estudient();
How Could I call the member function setSubject() ?

p->setSubject("science"); it is not possible.

Thank you
Jul 25 '07 #1
4 1192
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code:
Person* p;
*p=new Estudient();
How Could I call the member function setSubject() ?

p->setSubject("science"); it is not possible.
will work fine once you fix the error: p has to be an Estudient* and nort a Person*.

There is no setSubject() in Person.
Jul 25 '07 #2
ilikepython
844 Recognized Expert Contributor
Hello,

I have an inheritance hierarchy like this:
Expand|Select|Wrap|Line Numbers
  1. class Person{
  2. ...
  3. }
  4.  
  5. class HandlerSubjects{
  6.          public:
  7.                    virtual void setSubject(string);
  8. .....
  9. }
  10.  
  11.  
  12. class Estudient: public Person,public HandlerSubjects{
  13.  
  14. ....
  15.  
  16. }
  17.  
in main I have:
Expand|Select|Wrap|Line Numbers
  1. Person* p;
  2. *p=new Estudient();
How Could I call the member function setSubject() ?

p->setSubject("science"); it is not possible.

Thank you
Also, there shouldn't be a dereferencing sign when you assign to p. It should be this:
Expand|Select|Wrap|Line Numbers
  1. p = new Estudient();
  2.  
Jul 25 '07 #3
ohren
4 New Member
Also, there shouldn't be a dereferencing sign when you assign to p. It should be this:
Expand|Select|Wrap|Line Numbers
  1. p = new Estudient();
  2.  
Yes, but I have also the class Teacher that inherits from Person but not from HandlerSubjects, and I need to Know whit a pointer Person* if the object that points inherits or not from HandlerSubjects. How could I Know that?
Jul 26 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
What are you trying to do??

Multiple inheritance is not a beginner's thing. It's hard to do and you have you know your C++ in order to so it.

I don't think a Teacher can inherit from Person:
1) The Teacher has methods that are not appropriate to Person
2) Because of (1), you have to create Teacher objects and use Teacher*.

If you are trying to be object-orented, then the base class must have the methods used by the derived classes. That means you need to design your base class first. Then you write all of your code using base class pointers or references. Then you get that working.

Now you can derive a Teacher from Person and pass the address of the Teacher to the code expecting Person* or Person&. If you have done your design work, the program wwill compile and run with no changes required. Otherwise, your compile will fail.

I suggest writing the hierarchy on paper (complete with method names and which ones are virtual) before you start coding.
Jul 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4318
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
5
2161
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
20
10026
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
23312
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
47
3587
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
4862
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
15
28305
by: iKiLL | last post by:
hi all, I would like to be able to create an umbrella class for all my main global sections but I would still like to keep them all in separate file something like the below but I keep getting...
7
3712
by: Adam Nielsen | last post by:
Hi everyone, I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
47
3951
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
2
2527
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
0
7125
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
7002
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...
1
6887
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
5462
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,...
1
4910
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...
0
4590
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...
0
3093
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...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.