Function Pointers

Started by
23 comments, last by Shannon Barber 23 years, 10 months ago
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...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
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?

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
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
    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...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
    extern void APIENTRY glutDisplayFunc(void (*)(void));    

hum
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Drop the * in:

    void Sort(TREE *pTree, SORTPROC SortProc)    


Ahhh, thank you very much
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
They are required to load functions from a dynamically loaded library I think.

---
www.crazycrackerz.org

This topic is closed to new replies.

Advertisement