Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Shannon Barber

Function Pointers

This topic is 6717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m gonna keep a crackin at it, but if anyone has a short snippet readily availible, i would really appreiciate a function pointer class property example... The only book I have that even mentions them is LaMonthe''s "Tricks of the Window''s Game Programming Gurus" and there''s only two sentences, and 5 lines of code... not in a class...

Share this post


Link to post
Share on other sites
Advertisement
Function pointer class property? sounds scary.

Really, the only use (i have found) for function pointers are:

1) Arrays of function pointers
2) Simulating a class in C
3) For some crazy reason you need the address of the function

Edited by - ImmaGNUman on June 25, 2000 9:51:01 PM

Share this post


Link to post
Share on other sites
My version of a function pointer class property example...?...!

    
typedef int (*SORTPROC)(NODE *pNode, float fValue);

void Sort(TREE *pTree, SORTPROC *SortProc)
{
SortProc(pNode, fValue);
}

int NewSortProc(NODE *pNode, float fValue)
{
return pNode->fValue - fValue;
}

int Main()
{
Sort(pTree, (SORTPROC)NewSortProc);
}


Is this what you mean?

Share this post


Link to post
Share on other sites
Speed in the Message Pump

I don't want to have to make an object dereferenced function call for each WM_ case... particlularily the on idle Render();

something like

CWindow* MyWindow;
CWorld* Toril;
//init
//init
//init

MyWindow->SetRenderFunc(Toril->Render);
...
Just like the GLUT messsage pump...

You send WinProc as a funtion pointer... why can't I do it?

And that example LaMonthe gives don't work!

Edited by - Magmai Kai Holmlor on June 25, 2000 9:58:12 PM

Share this post


Link to post
Share on other sites
quote:
Original post by baskuenen

My version of a function pointer class property example...?...!

        
typedef int (*SORTPROC)(NODE *pNode, float fValue);

void Sort(TREE *pTree, SORTPROC *SortProc)
{
SortProc(pNode, fValue);
}

int NewSortProc(NODE *pNode, float fValue)
{
return pNode->fValue - fValue;
}

int Main()
{
Sort(pTree, (SORTPROC)NewSortProc);
}


Is this what you mean?





very close, thanks

Share this post


Link to post
Share on other sites
    
typedef int NODE;
typedef int TREE;
typedef int (*SORTPROC)(NODE *pNode, float fValue);
void Sort(TREE *pTree, SORTPROC *SortProc)
{
NODE* pNode;
float fValue;
SortProc(pNode, fValue);
}
int NewSortProc(NODE *pNode, float fValue)
{
return pNode->fValue - fValue;
}
int Main()
{
Sort(pTree, (SORTPROC)NewSortProc);
}

gives me a:
winmain.cpp(26) : error C2064: term does not evaluate to a function
on
SortProc(pNode, fValue);
in the Sort(TREE...) function...

Share this post


Link to post
Share on other sites
They are required to load functions from a dynamically loaded library I think.

---
www.crazycrackerz.org

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!