function pointer

This is a discussion on function pointer within the C++ Programming forums, part of the General Programming Boards category; I'm having a problem with a function pointer. The function pointer is in a struct and is being set to ...

  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 02: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,531
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,762
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 05: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, 06:06 PM

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