Pointeur de fonction vs fonction
Bonjour,
Pouvez vous m'expliquer la différence entre l'utilisation des pointeurs de fonction et directement la fonction dans les arguments?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| void test( void func() )
{
func();
};
void myFun()
{
std::cout << "this is another test" << std::endl;
};
int main()
{
test( myFun );
system("pause");
} |
Par rapport à
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| void test( void (*func)() )
{
func();
};
void myFun()
{
std::cout << "this is another test" << std::endl;
};
int main()
{
test( &myFun );
system("pause");
} |