Saturday, April 21, 2012

Functional pointer for beginner


This is how I started understanding concept of functional pointer in C++.
This helped me getting understanding of how methods are invoked which now helped me in implementation through System.Reflection in C#.


String^ CALL_FUNCTION() // sample function to invoke dynamically
{
       return "I write you read…";
}
void FuncMain(String^ (*pt2Func)())
{
       String^ i = pt2Func();
       Console::WriteLine(i);
}
int main(array ^args) // Console application
{
    Console::WriteLine("Hello World");
    FuncMain(&CALL_FUNCTION);
    return 1;
}

Output:
Hello World
I write you read…

No comments:

Post a Comment