Make an array of function pointers

This is a discussion on Make an array of function pointers within the C Programming forums, part of the General Programming Boards category; Hello, I am attempting to make an array of function pointers for iteration purposes. I have the following function prototypes: ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    59

    Make an array of function pointers

    Hello,

    I am attempting to make an array of function pointers for iteration purposes.

    I have the following function prototypes:

    Code:
    int bubble(int **, int, int);
    int quick(int **, int, int);
    int shell(int **, int, int);
    I want to make an array called functions. How do I do this? All my functions take the same arguments and return the same datatypes (int). How do I make an array out of these and how do I access the function once in the array?
    " . . . and I lay awake, big dreamers never sleep." - David Lee Roth

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Code:
    int main()
    {
        int (*functions[3])(int **, int, int) = { bubble, quick, shell };
    
        functions[0]( /* Put your arguments here */ ); // Call the first function, etc.
    
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    59
    Thanks,

    I would have never figured the (*functions[3]) part out.
    " . . . and I lay awake, big dreamers never sleep." - David Lee Roth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Replies: 1
    Last Post: 10-21-2007, 07:44 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. static array of function pointers within class
    By Yarbles in forum C++ Programming
    Replies: 6
    Last Post: 11-02-2005, 01:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21