Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6528641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:33:12+00:00 2026-05-25T09:33:12+00:00

I often read this statements on Stack Overflow. Personally, I don’t find any problem

  • 0

I often read this statements on Stack Overflow. Personally, I don’t find any problem with this, unless I am using it in a polymorphic way; i.e. where I have to use virtual destructor.

If I want to extend/add the functionality of a standard container then what is a better way than inheriting one? Wrapping those container inside a custom class requires much more effort and is still unclean.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:33:13+00:00Added an answer on May 25, 2026 at 9:33 am

    Maybe many people here will not like this answer, but it is time for some heresy to be told and yes … be told also that "the king is naked!"

    All the motivation against the derivation are weak. Derivation is not different than composition. It’s just a way to "put things together".
    Composition puts things together giving them names, inheritance does it without giving explicit names.

    If you need a vector that has the same interface and implementation of std::vector plus something more, you can:

    • use composition and rewrite all the embedded object function prototypes implementing function that delegates them (and if they are 10000… yes: be prepared to rewrite all those 10000) or…

    • inherit it and add just what you need (and … just rewrite constructors, until C++ lawyers will decide to let them be inheritable as well: I still remember 10 year ago zealot discussion about "why ctors cannot call each other" and why it is a "bad bad bad thing" … until C++11 permitted it and suddenly all those zealots shut up!) and let the new destructor be non-virtual as it was in the original one.

    Just like for every class that has some virtual method and some not, you know you cannot pretend to invoke the non-virtual method of derived by addressing the base, the same applies for delete. There is no reason just for delete to pretend any particular special care.

    A programmer who knows that whatever is not virtual isn’t callable addressing the base, also knows not to use delete on your base after allocating your derived.

    All the "avoid this", "don’t do that", always sound as "moralization" of something that is natively agnostic. All the features of a language exist to solve some problem. The fact a given way to solve the problem is good or bad depends on the context, not on the feature itself.

    If what you’re doing needs to serve many containers, inheritance is probably not the way (you have to redo for all). If it is for a specific case … inheritance is a way to compose. Forget OOP purisms: C++ is not a "pure OOP" language, and containers are not OOP at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time on StackOverflow though I read Coding Horror quite often.
When I read source from open source projects I often find a comment line
I often find myself using inline initialization (see example below), especially in a switch
My first question is, I often read about people using multiple dedicated servers to
I often read that lazy is not the same as non-strict but I find
I find myself often writing statements equivalent to: deleted_at = Time.at(data[:deleted_at]) if !data[:deleted_at].nil? i'd
I've often read that corporations will save millions once Internet Explorer 6 is finally
I've often read that in the Sun JVM short-lived objects (relatively new objects) can
When I read Django code I often see in models what is called a
when i read through source files of opensource projects i often come across some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.