473,320 Members | 1,883 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,320 software developers and data experts.

Multiple inheritance question

In C++, is it possible to design a class so that it will not allow
multiple inheritance?
Jun 27 '08 #1
6 1017
On May 2, 2:00 pm, t-tocs <scotty....@gmail.comwrote:
In C++, is it possible to design a class so that it will not allow
multiple inheritance?
That doesn't make sense. How can you design something to not allow you
to design it? If you design the class, you decide what it inherits...

class Derived : public Base
{
};

Derived inherits Base.

You probably meant, is it possible to design a class that will not
allow any derived class to inherit from anything but itself?
Probably. But, why would you want to?

Jun 27 '08 #2
No, I mean a base class, Base1, so that it will not allow the
following:

class Derive: public Base1, public Base2 {

}

but will allow:

class Derive: public Base1 {

}
On May 2, 3:17 pm, Christopher <cp...@austin.rr.comwrote:
On May 2, 2:00 pm, t-tocs <scotty....@gmail.comwrote:
In C++, is it possible to design a class so that it will not allow
multiple inheritance?

That doesn't make sense. How can you design something to not allow you
to design it? If you design the class, you decide what it inherits...

class Derived : public Base
{

};

Derived inherits Base.

You probably meant, is it possible to design a class that will not
allow any derived class to inherit from anything but itself?
Probably. But, why would you want to?
Jun 27 '08 #3
On May 2, 2:59 pm, t-tocs <scotty....@gmail.comwrote:
No, I mean a base class, Base1, so that it will not allow the
following:

class Derive: public Base1, public Base2 {

}

but will allow:

class Derive: public Base1 {

}
That's exactly what I said:
On May 2, 3:17 pm, Christopher <cp...@austin.rr.comwrote:

You probably meant, is it possible to design a class that will not
allow any derived class to inherit from anything but itself?
Probably. But, why would you want to?

Not without extreme hack like coding. Again, why would you want to? It
is extremely rude to limit the client of your class in a way that
would defy standard expectations. If you have some design that
requires it, there is probably something wrong with the design.
Jun 27 '08 #4
It is not for a particular reason.
I was just wondering if it was possible.

On May 2, 4:14 pm, Christopher <cp...@austin.rr.comwrote:
On May 2, 2:59 pm, t-tocs <scotty....@gmail.comwrote:
No, I mean a base class, Base1, so that it will not allow the
following:
class Derive: public Base1, public Base2 {
}
but will allow:
class Derive: public Base1 {
}

That's exactly what I said:
On May 2, 3:17 pm, Christopher <cp...@austin.rr.comwrote:
You probably meant, is it possible to design a class that will not
allow any derived class to inherit from anything but itself?
Probably. But, why would you want to?

Not without extreme hack like coding. Again, why would you want to? It
is extremely rude to limit the client of your class in a way that
would defy standard expectations. If you have some design that
requires it, there is probably something wrong with the design.
Jun 27 '08 #5
On May 2, 4:33 pm, t-tocs <scotty....@gmail.comwrote:
It is not for a particular reason.
I was just wondering if it was possible.
What made you think of this?

To let you prevent that, the compiler would have to go through the
base class list and if there was more than one base but one of the
base classes was marked with a hypothetical "no multiple inheritance"
property, fail to compile the code. C++ does not have that feature,
AFAIK.

If you are in a situation where having a class inherit from your class
and from something else would be a problem, the best solution is, of
course, to rethink your design. If you can't avoid it, the only thing
you can really do is clearly document the restriction and say "you
have been warned".

Jason
Jun 27 '08 #6
t-tocs wrote:
No, I mean a base class, Base1, so that it will not allow the
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Jun 27 '08 #7

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

Similar topics

6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
30
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
5
by: Tony Johansson | last post by:
Hello Experts! I just play around just to try to understand this about multiple inheritance. You have all the class definition below and at the bottom you have the main program. So here I...
22
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...
8
by: mmu2643 | last post by:
Hi, I had a question regarding multiple inheritance. class B1{ public: int a; };
4
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to...
60
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...
5
by: colint | last post by:
Hi I'm fairly new to c++ and I have a question regarding inheritance. I'm trying to create a class based on 2 inherited classes, e.g. class A { ... } class B: public A
2
by: mike | last post by:
Hello fellow C++ experts, is there any dramatic difference between multiple inheritance: struct MyType4 : MyType1, MyType2, MyType3 { int MyInt; }; and: struct MyType4 {
47
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.