Forwarding functions

Sometimes it is required to seperate the interface from implementation and 'forwarding functions' can be useful. The interface class can forward the work to the implementation keeping the interface clean and minimal.

The following is a simple example where function f() forwards its work to function g():



//g.h
#pragma once

bool
g(int x)
{

if
(x%2 == 0)
return
true;
else
return
false;
}



//f.h
#pragma once

bool
f(int x);


//f.cpp
#include<iostream>

#include "f.h"
#include "g.h"

bool
f(int x)
{

return
g(x);
}



//main.cpp
//Program tested on Microsoft Visual Studio 2008 - Zahid Ghadialy
#include<iostream>

#include "f.h"

using namespace
std;

int
main()
{

if
(f(20))
cout<<"TRUE"<<endl;
else

cout<<"FALSE"<<endl;

return
0;
}





There are couple of things to keep in mind when writing them. See here.

You can read more about seperating Interface and Implementation here.

Check out this stream