Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Functions stored in structure (http://www.go4expert.com/forums/functions-stored-structure-t6738/)

boschow 8Oct2007 19:15

Functions stored in structure
Hi all,
it is possible to declere a function within a structure, then in the main function with the use of the pointers call this function and assign the specific parameters . To make my idea clearer check out the sample code.

struct {
      int AND_function;
      int math_funct;
      int comp_funct;
      int regul_funct;

AND_function (parameter1, parameter2, . . .)

int main()
    struct functions *fun;
    function.AND_function(par.parameter1, par.parameter);

Thanks for your help,
Best regards,

shabbir 8Oct2007 21:53

Re: Functions stored in structure
As I can understand what you are looking for is possible in C++ but not the way you have written it.

boschow 8Oct2007 23:02

Re: Functions stored in structure
Is this possible only in C++ and not in C. If its possible in C could you write some examples for both program languages.

Best regards,

buddy 9Oct2007 00:39

Re: Functions stored in structure
No it is not possible to declare a function inside a Structure using c,
Only in c++ it is possible.

DaWei 9Oct2007 01:15

Re: Functions stored in structure
You should really specify whether you are talking about C or C++. Some people will tell you that C++ is a superset of C, but that isn't true. Structs are one of the notable exceptions.

You may define function pointers in C, and try to restrict their locale to a struct, but there are no guarantees that those who follow will adhere to your strictures.

All times are GMT +5.5. The time now is 04:03.