Heap and queue decision (theoretical)

I was going over some code and was wondering what everyone's idea was on composition versus inheritance. Say we have a class that is a Max heap that uses an array, then we want to build a priority queue that uses the Max heap. In the priority queue we would only be able to peek the top of the heap and remove the top item from the heap or add. What would you think is better, inheritance or composition?
Composition (or, in C++, private inheritance).

Alexandrescu and Sutter in 'C++ Coding Standards: 101 Rules, Guidelines, and Best Practices'
34. Prefer composition to inheritance.

Summary
Inheritance is the second-tightest coupling relationship in C++, second only to friendship. Tight coupling is undesirable and should be avoided where possible. Therefore, prefer composition to inheritance unless you know that the latter truly benefits your design.

...

Exceptions
Do use public inheritance to model substitutability. (See Item 37.)

Even if you don't need to provide a substitutability relationship to all callers, you do need nonpublic inheritance if you need any of the following ... :
• If you need to override a virtual function.
• If you need access to a protected member.
• If you need to construct the used object before, or destroy it after, a base class.
• If you need to worry about virtual base classes.
• If you know you benefit from the empty base class optimization ...
• If you need controlled polymorphism. ... substitutability relationship should be visible only to selected code ...
I would think that the best indicator is the keyword virtual.

If a base class does not contain any virtual functions it is a strong hint for composition.
If there are virtual functions you need to decide whether you need to override it -> inheritance or not -> composition.

The reason that composition is actually prefered is the flexibility.
The Heap class is a functional class by itself (can be instantiated) with no virtual functions. All the priority queue does is limit the functions of the heap class so it functions as a priority queue.

Would there be any security(integrity) concerns with using composition over inheritance? I have mainly studied inheritance in my studies so far, only real composition is probably with binary trees use of the node.
Topic archived. No new replies allowed.