私はいくつかのコードを書いて、それが動かないのではないかと怖くなったので、プロトタイプを書きました:
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <iostream>
class base {
private:
boost::function<void (int)> action;
protected:
virtual void onDataBaseReady(int i) { std::cout << i << std::endl; }
public:
void call() {
action(10);
}
base() {
action = boost::bind(&base::onDataBaseReady, this, _1);
}
};
class child : public base {
protected:
virtual void onDataBaseReady(int i) { std::cout << i+10 << std::endl; }
};
int main()
{
static child c;
c.call();
std::cin.get();
return 0;
}
コンパイルして動作します。(出力20
)。しかし、なぜ?また、VS2010でテストしましたが、プラットフォーム間で動作するかどうか疑問に思います(GCCでコンパイルされたと言います)?
主action = boost::bind(&base::onDataBaseReady, this, _1);
に私を怖がらせます-私たちは言い&base::
ます...