anoniem Geplaatst: 26 november 2002 Delen Geplaatst: 26 november 2002 Ik heb twee vraagjes: 1. Hoe kan achterhalen in een agumentloze functie wie/wat de 'sender' was, ofwel de aanroeper van de functie 2. Hoe kan ik een pointer naar een functie maken en die later weer aanroepen. Bedankt, Barry Quote Link naar reactie
anoniem Geplaatst: 28 november 2002 Auteur Delen Geplaatst: 28 november 2002 1) Geen idee 2) [code:1:a524badef8]#include <stdio.h> // a function taking no arguments and returning nothing // this function prints the famous string 'Hello world' void abc() { printf("Hello world\n"); } // another function returning a pointer to a char and taking an argument // this function multiplies the argument by 2 and // converts the result to a string char *def(int i) { static char buf[10]; sprintf(buf,"%d",2*i); return buf; } int main() { // pointers to function declaration void (*myfunc1)(); char *(*myfunc2)(int i); // other variables declaration char *ptr; // assign the functions myfunc1=abc; myfunc2=def; // call the functions myfunc1(); ptr=myfunc2(5); printf("%s\n", ptr); } [/code:1:a524badef8] De eerste twee regels in main beantwoorden je vraag, de overige laten zien hoe je vervolgens toekent en gebruikt. Overigens heeft dit niks met C++ te maken, maar met C. PS: De voorbeeld-code is geschreven in C en niet in C++. Quote Link naar reactie
anoniem Geplaatst: 28 november 2002 Auteur Delen Geplaatst: 28 november 2002 Nog even gezocht op het internet voor je: http://www.c-plusplus.de/tuts/cpp/cpp_functionpointers_eng.pdf Quote Link naar reactie
anoniem Geplaatst: 28 november 2002 Auteur Delen Geplaatst: 28 november 2002 Bedankt voor vraag 2 iig, Wat betreft vraag 1: Als het goed is (nog niet getest) bevat het object 'sender' in elke functie een pointer naar het aanroepende object/functie.... aan een pointer naar een object heb ik niks, maar wel als 'sender' naar de aanroepende functie wijst. Nog ff uitproberen dus.... Bedankt iedereen!!!! Quote Link naar reactie
Aanbevolen berichten
Om een reactie te plaatsen, moet je eerst inloggen