1、问题
C++很多地方需要函数指针回调,但是我理解还是不够深刻,今天再写了测试例子,方便后面更深入理解和记忆。
2、代码实现
A.h 文件实现
//
// A.h
// TestC++
//
// Created by 1111 on 17/8/17.
// Copyright © 2017年 sangfor. All rights reserved.
//#ifndef A_h
#define A_h#include <iostream>class A
{public:A(void){}~A(void){}typedef void(*fun)(int);typedef void(*fun1)(void*, int);void callback(fun f, int n){std::cout << "callback before" << std::endl;f(n);std::cout << "callback after" << std::endl;}void callback1(void *obj, fun1 f1, int n1){object = obj;f = f1;n = n1;}void exec(){std::cout << "callback1 before" << std::endl;f(object, n);std::co