🔒 Locked
Function Pointers
Advertisement
Original Post
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?
|
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
|
gives me a:
winmain.cpp(26) : error C2064: term does not evaluate to a function
on
SortProc(pNode, fValue);
in the Sort(TREE...) function...
|
hum
Ahhh, thank you very much
Argh, I still can't get it to work...
Any function pointer assignment snippets?
cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
when I try...
...
oh lordy, it's somethin' to do with the class contained function...
it works with a function not in a class...
...
ahhh duh, it's gotta be static - i already knew that
...
Oh this is getting ugly... It can't be static, I gotta access stuff in the calling object... could make the properties static...
...
Is it possible to resovle this?
cannot convert from 'void (__thiscall CWorld::*)(void)' to 'void (__cdecl *)(void)'
hum, i have an idea... more to follow, in case you ever want to do this...
Edited by - Magmai Kai Holmlor on June 25, 2000 10:56:47 PM
Any function pointer assignment snippets?
cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
when I try...
...
oh lordy, it's somethin' to do with the class contained function...
it works with a function not in a class...
...
ahhh duh, it's gotta be static - i already knew that
...
Oh this is getting ugly... It can't be static, I gotta access stuff in the calling object... could make the properties static...
...
Is it possible to resovle this?
cannot convert from 'void (__thiscall CWorld::*)(void)' to 'void (__cdecl *)(void)'
hum, i have an idea... more to follow, in case you ever want to do this...
Edited by - Magmai Kai Holmlor on June 25, 2000 10:56:47 PM
How about another approach:
Make your own virtual functions in a base class, and overide them in a derived class. This way you can let C++ handle the function ptrs for you. Why not put C++ to full use...
Short example:
Make your own virtual functions in a base class, and overide them in a derived class. This way you can let C++ handle the function ptrs for you. Why not put C++ to full use...
Short example:
|
I'll still have the same problem.
I'll have to derefence a pointer to get to the actual function I want to call.
The Render() function is in a different class...
Edited by - Magmai Kai Holmlor on June 25, 2000 11:06:09 PM
I'll have to derefence a pointer to get to the actual function I want to call.
The Render() function is in a different class...
Edited by - Magmai Kai Holmlor on June 25, 2000 11:06:09 PM
quote:
...
CWindow* MyWindow;
CWorld* Toril;
//init
//init
//init
MyWindow->SetRenderFunc(Toril->Render);
...
Solution:
|
Please tell me it works fine
Edited by - baskuenen on June 25, 2000 11:14:19 PM
Yes that works
I kinda didn't want to have the window contain the world
that pWorld->Paint()
is exactally what I don't want
i want:
Edited by - Magmai Kai Holmlor on June 25, 2000 11:17:42 PM
I kinda didn't want to have the window contain the world
that pWorld->Paint()
is exactally what I don't want
i want:
|
Edited by - Magmai Kai Holmlor on June 25, 2000 11:17:42 PM
Because 
I want to perfect the form, I'll use again with other repetitive function calls
such as
lpD3D7Device->DrawPrimitive...
Edited by - Magmai Kai Holmlor on June 25, 2000 11:26:25 PM
I want to perfect the form, I'll use again with other repetitive function calls
such as
lpD3D7Device->DrawPrimitive...
Edited by - Magmai Kai Holmlor on June 25, 2000 11:26:25 PM
Here we go again...hope this is the click (probably not, hehe
)
|
no no no
The renderer isnt a seperate class - it's in the CWorld
but that pWorld->Render()
---------------^^
Is what I want to eliminate.
such that CWindow::RenderFunc = CWorld::RenderFunc
Which I can do - CWorld::RenderFunc just needs to be static
But it can't be static & access object specific variables (unless they too are static)
So I need a CWindow::RenderFunc = pWorld->RenderFunc
Which I can't do yet
it'll change
pWorld->Render()
to
RenderFunc();
it won't make much a difference on that one function in the msgpump, but I think it will with all the D3D->PickAFunction's
Edited by - Magmai Kai Holmlor on June 25, 2000 11:39:27 PM
The renderer isnt a seperate class - it's in the CWorld
but that pWorld->Render()
---------------^^
Is what I want to eliminate.
such that CWindow::RenderFunc = CWorld::RenderFunc
Which I can do - CWorld::RenderFunc just needs to be static
But it can't be static & access object specific variables (unless they too are static)
So I need a CWindow::RenderFunc = pWorld->RenderFunc
Which I can't do yet
it'll change
pWorld->Render()
to
RenderFunc();
it won't make much a difference on that one function in the msgpump, but I think it will with all the D3D->PickAFunction's
Edited by - Magmai Kai Holmlor on June 25, 2000 11:39:27 PM
so close...
how do you get *this to it?
hum, me thinks this be impossible.
Edited by - Magmai Kai Holmlor on June 25, 2000 12:27:25 AM
how do you get *this to it?
hum, me thinks this be impossible.
|
Edited by - Magmai Kai Holmlor on June 25, 2000 12:27:25 AM
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement