Hello.
I read this article , there is a code
#include <stdio.h>
// A normal function with an int parameter
// and void return type
void fun(int a)
{
printf("Value of a is %d\n", a);
}
int main()
{
// fun_ptr is a pointer to function fun()
void (*fun_ptr)(int) = &fun;
/* The above line is equivalent of following two
void (*fun_ptr)(int);
fun_ptr = &fun;
*/
// Invoking fun() using fun_ptr
(*fun_ptr)(10);
return 0;
}
How I can change it, to make structure with function pointers? I want to make a sample OOP , such as String->strlen, String->strcat
This code dont work. How to make structure, that contains function pointers and can call functions?
typedef struct _api
{
void * f1;
void * f2;
} apis;
apis api;
int main()
{
(*api.f1) = &fun;
(*api.f1)(22); //Don't work!!!