0

Possible Duplicate:
When to use C++ private inheritance over composition?

Please help me with a scenario where composition is preferred over private inheritance.

Community
  • 1
  • 1
Kunal
  • 511
  • 2
  • 6
  • 12
  • 2
    That would be almost any scenario that you can think of :) – Sergey Kalinichenko Jun 14 '12 at 23:05
  • @dasblinkenlight...what are the tradeoffs of using private inheritance – Kunal Jun 14 '12 at 23:06
  • You give up access control to some degree: when you inherit privately, you can *accidentally* access a protected method or member. [Here](http://www.parashift.com/c++-faq-lite/private-inheritance.html#faq-24.3) is a good discussion of the subject. – Sergey Kalinichenko Jun 14 '12 at 23:09

1 Answers1

2

All the time. The real question is, when is private inheritance preferred over composition? Only when virtual functions are required. Else, always favour composition.

Puppy
  • 144,682
  • 38
  • 256
  • 465