Wednesday, February 6, 2013

function pointer

void noMoreMemory()
{
cerr<<"Unable to satisfy request for memory\n";
abort();
}

typedef void (*new_handler)();
new_handler set_new_handler(new_handler p) throw();

set_new_handler(noMoreMemory);

another example:


void Switch_With_Function_Pointer(float a, float b, float (*pt2Func)(float, float))
{
   float result = pt2Func(a, b);    // call using function pointer

   cout << "Switch replaced by function pointer: 2-5=";  // display result
   cout << result << endl;
}



Switch_With_Function_Pointer(2,5,&minus)

No comments:

Post a Comment