Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 04/05/26 10:06
TMFs on options in live trading
by Spirit. 03/26/26 19:52
TDAmeritrade plugin with new Schwab accountt?
by AndrewAMD. 03/24/26 17:11
Black Book, 4th edition
by jcl. 03/17/26 09:28
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (vince, TipmyPip), 4,609 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
ondrej, mredit, vestriaa, Lukudo, mldenoiser
19205 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Passing function pointers with parameters #229816
09/30/08 18:25
09/30/08 18:25
Joined: May 2008
Posts: 123
B
BES Offline OP
Member
BES  Offline OP
Member
B

Joined: May 2008
Posts: 123
Hey all!

I define a function pointer (globally defined):
void myFunc( myStruct* ptrStruct );

and give it a default definition:
void myFunc( myStruct* ptrStruct )
{
diag("\nOriginal function called, override this!");
}

Now the function I want to actually call:
void myDesiredFunc( myStruct* ptrStruct )
{
diag("\nCorrect function called");
}

Here's where the issue comes in- I need to set my function pointer in an intermediary function that is part of the API I'm building:
void SetMyFunction( function* newfunc )
{
myFunc = (function*)newfunc;
}

myStruct myStructInstance;
in main()
{
...
SetMyFunction( myDesiredFunc );
myFunc( &myStructInstance );
...
}

But the original function definition is used.
The function pointer (myFunc) and structure pointer parameter are globally defined. I've tried several casts in the SetMyFunction function (i.e. function*, function, void*, etc.)
Anyone see what I'm missing? Do I need to somehow specify the parameter type in my cast; something like
myFunc = (function(myStruct*))newfunc; //??

Thanks so much for your time!

Re: Passing function pointers with parameters [Re: BES] #229824
09/30/08 19:32
09/30/08 19:32
Joined: May 2008
Posts: 123
B
BES Offline OP
Member
BES  Offline OP
Member
B

Joined: May 2008
Posts: 123
Alright, got it:

void SetMyFunction( void* newfunc )
{
myFunc = (function*)newfunc;
}

The problem was using the same name for myFunc and the default definition. To get around this I just say:
void myFunc( myStruct* ptrStruct );

and

void defaultFunc( myStruct* ptrStruct );
{
diag("\nDefault function called!");
}

then in main:

myFunc = defaultFunc

Then I'm able to set myFunc to myDesiredFunc later on.

Hope this helps someone in the future! Cheers!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1