我想知道是否有人可以幫我解決這個問題。我一直在閱讀,這是在VS2010中使用std :: make_pair的一些問題,因爲它被重載,並且我找到了一些可行的解決方法,但是,我無法找到一種方法使它在這裏工作我。std :: make_pair在VS2010中的boost :: bind錯誤
下面是代碼的一部分,所以你可以看看:
namespace tree {
#define container std::vector
typedef container<IConnType const*> node_data;
///tree node's brief
struct tree_node
{
STD_STRING name;
node_data types;
};
struct branch;
typedef container<branch> sub_tree;
///branch's brief
struct branch
{
tree_node node;
sub_tree tree;
};
}
template<typename T>
///address of's brief
struct address_of
{
T* operator()(T& x) const
{
return &x;
}
T const* operator()(T const& x) const
{
return &x;
}
};
typedef std::pair<tree::branch*,HTREEITEM> step_info;
std::vector<step_info> steps;
/// after we fill steps ///
HTREEITEM new_item = m_conntree.InsertItem(&tvi); // m_conntree is a CTreeCtrl; tvi is a TVINSERTSTRUCT
std::transform(step.first->tree.begin()
, step.first->tree.end()
, std::back_inserter(steps)
, boost::bind(&std::make_pair<tree::branch*,HTREEITEM>
, boost::bind<tree::branch*>(address_of<tree::branch>()
, _1
)
, new_item
)
);
的問題是在這裏(代碼剩下的只是給一個想法):
std::transform(step.first->tree.begin()
, step.first->tree.end()
, std::back_inserter(steps)
, boost::bind(&std::make_pair<tree::branch*,HTREEITEM>
, boost::bind<tree::branch*>(address_of<tree::branch>()
, _1
)
, new_item
)
);
我試圖做一個鑄件(正如我在另一個線程讀過),但它沒有工作......這就是我曾嘗試:
typedef std::pair<tree::branch*,HTREEITEM> (*MakePairType)(tree::branch*,HTREEITEM);
std::transform(step.first->tree.begin()
, step.first->tree.end()
, std::back_inserter(steps)
, boost::bind((MakePairType)&std::make_pair<tree::branch*,HTREEITEM>
, boost::bind<tree::branch*>(address_of<tree::branch>()
, _1
)
, new_item
)
);
我希望的yone可以幫助我用這個...我一直堅持很長時間試圖編譯這個項目...
順便說一下,它引發了很多錯誤在boost :: bind(超過一百)...並取出boost :: bind,它給了我關於不知道std :: make_pair使用哪個超載的錯誤,
關心,並提前致謝!
爲什麼不使用lambda並且完全避免所有'bind'廢話? – ildjarn
如果你沒有lambda支持,編寫一個簡單的函子可能會更容易,它可以做你想做的。 –
'#定義容器標準::矢量'Egads! –