需要參數的方法我有一個這樣的結構:使用bind1st爲參照
struct A {
void i(int i) {}
void s(string const &s) {}
};
現在,當我試試這個:
bind1st(mem_fun(&A::i), &a)(0);
bind1st(mem_fun(&A::s), &a)("");
第一行編譯OK,但第二生成一個錯誤:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(299): error C2535: 'void std::binder1st<_Fn2>::operator()(const std::basic_string<_Elem,_Traits,_Ax> &) const' : member function already defined or declared
with
[
_Fn2=std::mem_fun1_t<void,A,const std::string &>,
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(293) : see declaration of 'std::binder1st<_Fn2>::operator()'
with
[
_Fn2=std::mem_fun1_t<void,A,const std::string &>
]
c:\work\sources\exception\test\exception\main.cpp(33) : see reference to class template instantiation 'std::binder1st<_Fn2>' being compiled
with
[
_Fn2=std::mem_fun1_t<void,A,const std::string &>
]
可能是什麼問題?我怎麼修復它?
編輯:
似乎任何引用的說法是一個問題。因此,如果我將i
方法更改爲void i(int &i) {}
,我收到類似的錯誤。
考慮到我們是在2011年,並有C++ 11你可能想看看C++ 11S'的std :: bind'或'的boost ::綁定'這使得這些事情的數量級更容易處理。 – PlasmaHH
@PlasmaHH:不幸的是,我不能在這個項目中使用C++ 11。 –
也不是'boost :: bind'? – PlasmaHH