Re: private inheritance vs containment
In article <f3d8g6$o8l$1@news.Stanford.EDU>, Seungbeom Kim
<musiphil@bawi.org> wrote:
However, I cannot imagine a case where private inheritance will give
you any extra performance over containment. Can you give an example?
struct Private
{
void foo(){};
}
class A:private Private
{
public:
using Private::foo;
};
class B
{
Private b;
public:
void foo() {b.foo();}
};
A a;
B b;
b.foo() directly calls B::foo(), which calls Private::foo() but
a.foo() directly calls Private::foo(). Your compiler probably
will optimize the excess call away but private inheritance guarantees
the direct call of Private::foo().
Further private inheritance gives instant documentation that A uses
foo of Private with no changes. and using statements are ussually
shorter and less error prone than forwarding functions. Take your
pick.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]