Hi Folks,
I read a statement "Pointers to functions and pointers to members cannot be assigned to void *s" in the book "C++ Programing Language 3rd Edition", Section 5.6, Pointer to Void.
I believe I have tried to create a similar situation but it works.
Is my understanding wrong??? or VC++ 6.0 yet to implement this functionality???
The code that worked is given below.
//////////////////////////////////////////////////////////// the actual program /////////////////
///////////////////////// end of programCode:#include <iostream> // function declarations void display(); void test_void_pointers(void *); // function definitions void display() { std::cout << "I am working" << std::endl; } void test_void_pointers(void *vp) { // explicit type converstion void (*fp)() = (void (*)()) vp; // call display() using pointer to function fp(); } int main() { // passing the address of the function display. // it is being received in a void *vp test_void_pointers(display); void (*fp)() = display; test_void_pointers(fp); return 0; }



LinkBack URL
About LinkBacks



