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 8208363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:19:00+00:00 2026-06-07T09:19:00+00:00

Possible Duplicate: Prefer composition over inheritance? A general question which I stumbled upon several

  • 0

Possible Duplicate:
Prefer composition over inheritance?

A general question which I stumbled upon several times recently: What are the advantages and disadvantages of deriving as opposed to containing?

To be more specific:

class A : public std::vector<int> {};

or

class B {public: std::vector<int> elem;}

?

Of course in a production code I would declare elem as private and implement public getters and setters.

Is there a general recommendation?

  • 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-06-07T09:19:02+00:00Added an answer on June 7, 2026 at 9:19 am

    The general recommendation is to not derive from standard library containers. See also this questions answers.

    The first answer to this question gives a note on the Liskov substitution principle which could be your answer.

    Substitutability is a principle in object-oriented programming. It states that, in a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e., objects of type S may be substituted for objects of type T) without altering any of the desirable properties of that program (correctness, task performed, etc.).

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

Sidebar

Related Questions

Possible Duplicate: Prefer composition over inheritance? I wonder, why (or in which cases) should
Possible Duplicate: When to prefer JSON over XML? i wonder if JSON is the
Possible Duplicate: B- trees, B+ trees difference What are the advantages/disadvantages of BTree+ over
Possible Duplicate: C++ When should we prefer to use a two chained static_cast over
Possible Duplicate: Should I always prefer MySQL InnoDB over MyISAM? Under what conditions should
Possible Duplicate: When should one use final? When should Java programmers prefer to use
Possible Duplicate: Javascript === vs == : Does it matter which “equal” operator I
Possible Duplicate: decimal vs double! - Which one should I use and when? I'm
Possible Duplicate: Do you prefer explicit namespaces or 'using' in C++? I am a
Possible Duplicate: C++ singleton vs completely static object Hi, why should I prefer a

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.