Re: what is forwarding function by Carl
Carl
Thu Sep 30 09:03:13 CDT 2004
david li wrote:
> Hi all:
>
> I read a document. it says "Forwarding functions are to be inline.".
> what is forwarding function.
It's a function that simply "forwards to" another function
class B
{
protected:
void f();
};
class D : public B
{
public:
void g() { f(); }
};
In the example above, D::g() would be a forwarding function (and inline)
since all it does is call B::f(). This is one way (not the only way) to
expose (make public) a protected inherited function.
A typical use of forwarding functions is when you have to write an "adapter"
class. Such classes expose one interface and delegate to another interface.
For example, you might write a string class that exposes the Rogue-Wave
RWString interface but delegates to a std::string implementation internally.
Many (or all) of the member functions of such a class would be forwarding
function.
Some people will give a tighter definition of a forwarding function,
restricting it to cases like D::g() above where the forwarding function and
the forwarded-to function have identical signatures.
HTH
-cd