[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] array af funktioner, initialisering og kald af dem.



Hvis det nu skal være C++ (--) = C

HC
-----------------------------------
sslug@sslug:/tmp$ ./decode
tdecode: hej der
vdecode: hej der
adecode: hej der

-----------------------------------
#include <iostream>

int adecode(char *p, char *t);
int vdecode(char *p, char *t);
int tdecode(char *p, char *t);

int (*f[3])(char *p, char *t);

void setup(int index, int (*decode)(char *p, char *t)) {
        f[index] = decode;
}

int call_f(int index, char *p, char *t) {
        return f[index](p, t);
}

int main (int argc, char *argv[])
{
        setup(0, adecode);
        setup(1, vdecode);
        setup(2, tdecode);
        for (int i=2; i>=0; --i)
                call_f(i, "hej", " der");
        return 0;
}

int adecode(char *p, char *t)
{
        std::cout << "adecode: " << p << t << std::endl;
        return 0;
}

int vdecode(char *p, char *t)
{
        std::cout << "vdecode: " << p << t << std::endl;
        return 0;
}

int tdecode(char *p, char *t)
{
        std::cout << "tdecode: " << p << t << std::endl;
        return 0;
}



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-03-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *