Thread: function pointer

  1. #1
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215

    Wink Nobody reads topics titled 'Function Pointer'!

    I'm having a problem with a function pointer. The function pointer is in a struct and is being set to a function in a derived class(the class name isn't certain).


    Code:
    typedef struct StateManager
    {
    	D3DRENDERSTATETYPE RenderState[10];
    	DWORD Value[10];
    	void (*render)(void); // FUNCTION POINTER
    Code:
    virtual void __cdecl Render(); //FUNCTION DECLARATION
    RenderResources is the predefined struct. Render is the overloaded Render function.
    Code:
    RenderResources->render = Render;
    And the error:
    Code:
    error C2440: '=' : cannot convert from 'void (__cdecl ArkTest::* )(void)' to 'void (__cdecl *)(void)'
    I'm guessing I need to change the function pointer declaration to contain ArkTest:: but I don't want to do that because there's no certainty the overloaded function will be ArkTest. However, I'm new to function pointers and I'm probably missing something. Any Ideas?
    Last edited by durban; 10-08-2005 at 01:56 AM.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You want a pointer to member function, not a pointer to function. __cdecl is also a compiler specific extension, which I'll ignore.

    To get a pointer to member function use;
    Code:
    class X
    {
          void (X::*render)();
    
          public:
             X() {render = &X::Render;};
             void Render();
             void DoRender() {this->(*render)();};
    };

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    A really good and detailed explanation
    http://www.newty.de/fpt/index.html
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    AYE! Thanks for the reply, but I don't think you read my whole post. Now, the problem is..I don't know the member's class. =X Is there any way to make a pointer to a class member that you don't know? Such as a derived class =)
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Function Pointer help
    By Skydt in forum C Programming
    Replies: 5
    Last Post: 12-02-2005, 09:13 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM