|
-
Oct 18th, 2004, 06:28 PM
#1
Thread Starter
Hyperactive Member
Function declare for use of function as param
Ok if I declare my functions in a class as.
SetEvent(long tEvent,void *funcname);
MSVC lets me do
void SomeFunc();
void SomeotherFunc(int, int);
....
SomeClass someobject;
....
someobject.SetEvent(1,SomeFunc);
someobject.SetEvent(1,SomeotherFunc);
However Ming32 errors on both.
I have to cast it which I dont want to do.
What is the correct way to declare a function that takes a function as a parameter. Or is it possible?
packetvb
-
Oct 18th, 2004, 06:39 PM
#2
Not sure, but I think you have to make a pointer to that function, have you done that?
-
Oct 18th, 2004, 06:51 PM
#3
Thread Starter
Hyperactive Member
Thats what I dont want to have to do.
I dont want to cast it and I dont want to have to create a pointer for the function.
I guess I want to declare in the function of the class to expect a pointer to a function.
Hows that done?
-
Oct 18th, 2004, 08:07 PM
#4
Not NoteMe
Not quite sure what you want, but i use this as a parameter for some of my functions.
void (*<Variable Name>)(<Parameter List For Function>)
You'd pass in something like &MyFunction
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Oct 18th, 2004, 08:11 PM
#5
try something like this:
Code:
// pfMyFunction is a pointer to a void function that takes 2 int arguments
typedef void(*pfMyFunction)(int a, int b);
// this is an example of a pfMyFunction
void MyFunction(int a, int b)
{
}
void FuncAsArg(pfMyFunction func)
{
func(1, 3);
}
int main()
{
FuncAsArg(MyFunction);
return;
}
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Oct 18th, 2004, 08:31 PM
#6
Thread Starter
Hyperactive Member
Thanks for the replies.
SLH,
Nope doesnt work Ming complains about the function def.
sunburnt,
Thats exacetly what I wanted to stay away from.
Oh well, I guess ill just cast it using (void*) before the function names. That way itll work on any func decl.
Kinda odd that MSVC excepts the func name only and Ming requires the cast. Just means Ill have to do a fix up for ming compilers after the conversion from basic to c++.
Thanks guys/girls. 
packetvb
-
Oct 18th, 2004, 09:16 PM
#7
The code I showed does not cast to a void* -- it works on any function fitting the declaration void somefunc(int, int).
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|