boost::bind And Objective-C
来源:互联网 发布:金蝶利润表取不到数据 编辑:程序博客网 时间:2024/06/07 23:06
http://stackoverflow.com/questions/1020028/can-i-boostbind-to-an-objective-c-function
You should be able to bind to a message implementation (IMP
), which are just plain C functions with two hidden parameters, self
and _cmd
of types id
and SEL
respectively.
EDIT: Just tested the following complete example, and it appears to work.
#include <stdio.h>#include <boost/bind.hpp>#include <Foundation/NSObject.h>@interface MyClass : NSObject{}-(int) doSomething:(int)arg;@end@implementation MyClass-(int) doSomething:(int)arg{ printf("doSomething: self=0x%08x _cmd=0x%08x\n", self, _cmd); return arg + 1;}@endint main(void){ MyClass *myObj = [[MyClass alloc] init], *otherObj = [[MyClass alloc] init]; typedef int (*MyFunc)(id, SEL, int); SEL doSomething_sel = @selector(doSomething:); MyFunc doSomething_impl = (MyFunc)[myObj methodForSelector:doSomething_sel]; // bind self & _cmd arguments: // calls [myObj doSomething:x] int result = boost::bind(doSomething_impl, myObj, doSomething_sel, _1)(14); printf("result1: %d\n", result); // bind _cmd & arg: // calls [otherObj doSomething:3] result = boost::bind(doSomething_impl, _1, doSomething_sel, 42)(otherObj); printf("result2: %d\n", result); return 0;}
gcc objcbind.mm -o objcbind -framework Foundation -lstdc++
- boost::bind And Objective-C
- [C++] boost::function boost::bind 与 回调
- C++:boost::bind的一些用法
- C++“准”标准库Boost学习指南(9):Boost.Bind
- boost.bind
- boost::bind
- boost::bind
- boost::bind
- Boost::bind
- Boost::bind
- bind -boost
- boost::bind()
- boost bind
- boost::bind
- boost::bind
- boost::bind
- boost bind
- boost::bind
- 段晓宇
- 地方纷纷
- java 压缩和解压缩
- get、load与懒加载小总结
- Android 源码编译的系统apk如何安装到手机
- boost::bind And Objective-C
- MySQL性能优化的最佳20+条经验
- 北科大女生受托杀人被判无期
- 密码被改了
- Java工作环境搭建
- 连密码都没有安全保障的社区,让我们如何能在这里交流。
- .net 转载
- 杂谈
- autorun.inf的删除与防范。