我還有一個關於函數引用的問題。 例如,我有這樣的定義:使用函數引用
typedef boost::function<bool (Entity &handle)> behaviorRef;
std::map< std::string, ptr_vector<behaviorRef> > eventAssociation;
的第一個問題是:怎樣將值插入諸如地圖對象?
我想:
eventAssociation.insert(std::pair< std::string, ptr_vector<behaviorRef> >(eventType, ptr_vector<behaviorRef>(callback)));
但錯誤:
no matching function for call to ‘boost::ptr_vector<boost::function<bool(Entity&)> >::push_back(Entity::behaviorRef&)’
我undersatnd它,但是無法進行可行的代碼。
第二個問題是如何調用這些函數? 例如,我有一個行爲參考的對象,如何通過boost :: bind來調用它與傳遞我自己的值?
作爲前端,則可以使用'的std :: make_pair()的',而不是直接構建在一對;這可以避免必須寫出對的模板參數。 – 2010-06-01 13:22:48
@ james-mcnellis感謝您的提示! – Ockonal 2010-06-01 13:25:33