Multiple inheritance question

Discussion in 'C++' started by t-tocs, May 2, 2008.

  1. t-tocs

    t-tocs Guest

    In C++, is it possible to design a class so that it will not allow
    multiple inheritance?
    t-tocs, May 2, 2008
    #1
    1. Advertising

  2. t-tocs

    Christopher Guest

    On May 2, 2:00 pm, t-tocs <> wrote:
    > 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?
    Christopher, May 2, 2008
    #2
    1. Advertising

  3. t-tocs

    t-tocs Guest

    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 <> wrote:
    > On May 2, 2:00 pm, t-tocs <> wrote:
    >
    > > 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?
    t-tocs, May 2, 2008
    #3
  4. t-tocs

    Christopher Guest

    On May 2, 2:59 pm, t-tocs <> wrote:
    > 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 <> wrote:
    > >
    > > 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.
    Christopher, May 2, 2008
    #4
  5. t-tocs

    t-tocs Guest

    It is not for a particular reason.
    I was just wondering if it was possible.

    On May 2, 4:14 pm, Christopher <> wrote:
    > On May 2, 2:59 pm, t-tocs <> wrote:
    >
    > > 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 <> wrote:

    >
    > > > 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.
    t-tocs, May 2, 2008
    #5
  6. t-tocs

    Guest

    On May 2, 4:33 pm, t-tocs <> wrote:
    > 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
    , May 2, 2008
    #6
  7. t-tocs

    Default User Guest

    Re: Multiple inheritance question - TPA

    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>
    Default User, May 3, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,134
    Martijn van Steenbergen
    Dec 21, 2003
  2. cppsks
    Replies:
    0
    Views:
    814
    cppsks
    Oct 27, 2004
  3. karthikbalaguru
    Replies:
    9
    Views:
    1,033
  4. Daniel Pitts
    Replies:
    27
    Views:
    1,892
    Mike Schilling
    Feb 27, 2008
  5. Rouslan Korneychuk
    Replies:
    8
    Views:
    593
    Rouslan Korneychuk
    Feb 10, 2011
Loading...

Share This Page