pointers to funtions

This is a discussion on pointers to funtions within the C++ Programming forums, part of the General Programming Boards category; i have this code Code: #include <stdio.h> #include <iostream> using namespace std; void DisplayMine() { cout <<"dgd"; } struct mine ...

  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
    Katy, Texas
    Posts
    2,309
    Try this:
    Code:
    mineTmp[0].dd = DisplayMine;
    mineTmp[0].dd();
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

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, 04:31 AM
  2. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 06:19 AM
  3. Replies: 7
    Last Post: 05-19-2010, 03: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

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