In article <11**********************@t31g2000cwb.googlegroups .com>,
"al pacino" <si*************@gmail.com> wrote:
hi,
is there any advantage of using private inheritance over composition
and vice versa.
under what condition/s should we chose one over the other.
class Base {
public:
// lots of functionality
virtual void fun();
};
Now, assume we want to write a class that can use Base's functionality
and must override fun, but shouldn't be useable as a Base*. We have two
choices.
class Derived : public Base {
public:
void fun();
};
class User {
Derived d;
public:
//stuff
};
or simply:
class User : private Base {
void fun();
public:
// stuff
};
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.