// @topic W090105 C function pointer demo
// @brief Using function pointers and typedef

#include <iostream>
#include <cstdlib>

void foo( int param )
{
    std::cout << __FUNCTION__ << "(" << param << ")\n";
}

void bar ( int param1, int param2 )
{
    std::cout << __FUNCTION__ << "(" << param1 << "," << param2 << ")\n";
}

// typedef creates an alias name for an existing data type

// Make ColorT an alias for an int:
typedef int ColorT;

// Make Pf an alias for a pointer to a function
// that takes two ints and returns a void:
typedef void ( *Pf ) ( int, int );

int main()
{
    void foo( int );       // function declaration
    foo( 111 );            // normal function call

    void ( *pfoo )( int ); // pfoo declared as a ptr to function
    pfoo = &foo;           // pfoo now points to foo
    pfoo( 222 );           // function call via ptr to function

    Pf pbar;               // another function ptr
    pbar = &bar;           // now it points to function bar
    pbar( 333, 444 );      // function call via ptr to function

    system("pause");
    return 0;
}