MoDDiB
Messages postés546Date d'inscriptionmardi 26 novembre 2002StatutMembreDernière intervention 4 mai 2007
-
25 févr. 2004 à 13:42
MoDDiB
Messages postés546Date d'inscriptionmardi 26 novembre 2002StatutMembreDernière intervention 4 mai 2007
-
25 févr. 2004 à 22:43
Supposons que j'ai la fonction
void Fonction(int test,int t);
appartenant a la classe Cclass.
Quelle est la syntaxe pour creer un pointeur vers cette fonction?
Normalment c'est :
void (*Fonction)(int,int);
Mais cela ne marche pas vu qu'ici ma fonction appartient a la classe :( merci bcoup ^^
Hylvenir
Messages postés364Date d'inscriptionmercredi 11 février 2004StatutMembreDernière intervention 5 octobre 20062 25 févr. 2004 à 13:59
Peut être que ça répond à ta question ?
#include
class A {
public:
void fonction( int a, int b )
{ std::cout << a << ' ' << b << std::endl; }
void fonction2( int a, int b )
{ std::cout << b << ' ' << a << std::endl; }
};
int main() {
void (A::*fct)(int, int ) = &A::fonction;
A a;
(a.*fct)( 2, 3 );
fct = &A::fonction2;
(a.*fct)( 2, 3 );
}