Requesting sample code!
- From: Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Nov 2008 20:13:00 -0800
Hello,
I am looking into pointers to functions and I am looking at stuff like this:
==================
#include <stdio.h>
int any_function(int(*pfun)(int, int), int x, int y){
return pfun(x, y);
}
int sum(int x, int y){
return x + y;
}
int product(int x, int y){
return x * y;
}
int difference(int x, int y){
return x - y;
}
int main(void){
int a = 10;
int b = 5;
int result = 0;
int (*pf)(int, int);
pf = sum; /* Pointer to sum function */
result = any_function(pf, a, b);
//result = any_function(sum, a, b);
printf("\nresult = %d", result );
result = any_function(product,a, b);
printf("\nresult = %d", result );
printf("\nresult = %d\n", any_function(difference, a, b));
return 0;
}
===========================
But I am looking all over for sample code which embeds the functions or
pointers to function in structures. In other words I am looking for sample
code which would show how to include funtions or pointers to functions as
members of a struct. Very similar ... you know like we do in C++ when we have
methods in our classes. I want to do the same thing with structures. Is this
possible and can someone direct me to some samples or books which illustrate
on how to code this.
I would show an example but I don't even know where to start to code this,
but I know it is possible because I have seen something similar to what I
want to do at:
http://bytes.com/forum/thread583012.html
But I would like a full description of how to implement functions and
pointers to functions as members of a struct which is not posted as a
question but rather as a tutorial or book!
All help and suggestions sincerely appreciated!
P.S. I have not yet looked at amazon.com for any potential books!
--
Best regards
Roberto
.
- Follow-Ups:
- Re: Requesting sample code!
- From: Guido Franzke
- Re: Requesting sample code!
- From: Alex Blekhman
- Re: Requesting sample code!
- From: Barry Schwarz
- Re: Requesting sample code!
- Prev by Date: Re: Simple va_list question.
- Next by Date: Re: Requesting sample code!
- Previous by thread: Simple va_list question.
- Next by thread: Re: Requesting sample code!
- Index(es):
Relevant Pages
|
Loading