Function Pointers
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...
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
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
My version of a function pointer class property example...?...!
Is this what you mean?
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?
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
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
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
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...
They are required to load functions from a dynamically loaded library I think.
---
www.crazycrackerz.org
---
www.crazycrackerz.org
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement