1. 函数指针
#include
typedef void (*func)(void);
void func1(void)
{
std::cout << "hello func1" << std::endl;
}
void func2(void)
{
std::cout << "hello func2" << std::endl;
}
int main(int argc, char *argv[])
{
func fc = func1;
fc();
fc = func2;
fc();
return 0;
}
2. function
#include
#include
void func1(void)
{
std::cout << "hello func1" << std::endl;
}
void func2(void)
{
std::cout << "hello func2" << std::endl;
}
int main(int argc, char *argv[])
{
std::function func(&func1);
func();
func = &func2;
func();
return 0;
}