Inheritance in STL

Discussion in 'C++' started by iskhan, Jun 18, 2009.

  1. iskhan

    iskhan New Member

    Joined:
    Jun 18, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Why STL is not incorraging inheritance?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Any modern world software development process also suggest to avoid Inheritance as its very tightly coupled relationship.
     
  3. iskhan

    iskhan New Member

    Joined:
    Jun 18, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Inheritance is one of the key element in OOP so what is the other way?
    If we use Inheritance in STL what kind of problems we face?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Inheritance has its own kind of problem and one of the famous and very basic is multiple inheritance.
     
  5. iskhan

    iskhan New Member

    Joined:
    Jun 18, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I know if we use multiple inheritance it may be possible "Deadly Diamond of Death" formed.but I need to know why inheritance is avoid to use in Standard Template Library??If we use it what kind of problem we face??I sure you understand my question.
     
  6. Aesop

    Aesop New Member

    Joined:
    Jun 19, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    If you are inheriting from a class, it should (usually) have a virtual destructor. But for efficiency reasons STL containers don't define virtual destructors.

    So that's one reason. There may be others.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice