473,563 Members | 2,681 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("sc ience"); it is not possible.

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

p->setSubject("sc ience"); 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("sc ience"); 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
4323
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
5
2169
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 multiple inheritance still be avoided? If yes, why multiple inheritance is introducted into C++?
20
10046
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 advance for enlightment ... here's the snippet #!/usr/bin/python
22
23329
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 examples?
47
3613
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
4889
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 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%)...
15
28325
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 an error saying you are not allowed Multiple base classes. /// <summary>
7
3722
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 goes like this: Shape | +-- Ellipse | +-- Circle
47
3966
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 support multiple inheritance. In C++ for instance I noticed that the compiler flags an error if you use the "ref" keyword on a class with multiple...
2
2553
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). -- Paul for cls in (A,B,C,D): seen = set()
0
7659
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...
0
7882
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. ...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6244
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...
1
5481
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...
0
5208
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...
0
3634
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...
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
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...

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.