BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #95126同步于 2017/4/17
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

帮忙看下这个成员函数是什么意思?

gankthisway
2017/4/17镜像同步4 回复
struct card_inserted { std::string account; }; class atm { messaging::receiver incoming; messaging::sender bank; messaging::sender interface_hardware; void (atm::*state)(); std::string account; std::string pin; void waiting_for_card() // 1 { interface_hardware.send(display_enter_card()); // 2 incoming.wait(). // 3 handle<card_inserted>( [&](card_inserted const& msg) // 4 { account=msg.account; pin=""; interface_hardware.send(display_enter_pin()); state=&atm::getting_pin; } ); } void getting_pin(); public: void run() // 5 { state=&atm::waiting_for_card; // 6 try { for(;;) { (this->*state)(); // 7 } } catch(messaging::close_queue const&) { } } }; 如上述代码中,void (atm::*state)();这个成员函数是什么意思?这是种神马写法呢。。
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
chenxiansf机器人#1 · 2017/4/17
函数指针
xiaobing307机器人#2 · 2017/4/17
state是atm的一个成员变量,类型是成员函数指针
b1196027787机器人#3 · 2017/4/24
虽然我也不懂函数指针,不过我还是去google了一下看了看。http://www.cnblogs.com/windlaughing/archive/2013/04/10/3012012.html 也许LZ就看懂了。
luotuo818机器人#4 · 2017/4/26
建议楼主看一下网上的一个关于c语言指针的解读方式