Thread: pointers to funtions

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    19

    Question pointers to funtions

    i have this code

    Code:
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    
    
    void DisplayMine()
    {
    	cout <<"dgd";
    }
    
    struct mine
    {
    	void (*dd)(void);
    };
    
    int main()
    {
        void (*foo)(int);
    
    	mine  mineTmp[10];
    	mineTmp[0].dd = &DisplayMine;
    
    	mineTmp[0].dd;
    
    	system ("pause");
        return 0;
    }

    what i want to do is load differnet pointers to different funtions in an array .
    then just call the funtion by going something like mineTmp[1];

    its for finite state machine , i figure you can do this some how , can ayone tell me how to do this please

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Try this:
    Code:
    mineTmp[0].dd = DisplayMine;
    mineTmp[0].dd();
    Mainframe assembler programmer by trade. C coder when I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays with pointers
    By Niels_M in forum C Programming
    Replies: 18
    Last Post: 07-31-2010, 03:31 AM
  2. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 05:19 AM
  3. Replies: 7
    Last Post: 05-19-2010, 02:12 AM
  4. pointers to arrays
    By rakeshkool27 in forum C Programming
    Replies: 1
    Last Post: 01-24-2010, 07:28 AM
  5. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM