0
点赞
收藏
分享

微信扫一扫

推迟函数执行方法


#include <iostream>
#include <string>
#include <memory>

#define defer(fun,p) std::shared_ptr<void> defer_##p(p,std::bind(fun,std::placeholders::_1))
void fun(int *p) {
std::cout << "p = " << *p << std::endl;
}
int main() {
int a = 10;
int *p = &a;
defer(fun, p);
std::cout << "hello world." << std::endl;

return 0;
}

 

举报

相关推荐

0 条评论