Mam struct tak:Korzystanie bind1st do metody, która bierze argumentu przez odniesienie
struct A {
void i(int i) {}
void s(string const &s) {}
};
Teraz, gdy próbuję to:
bind1st(mem_fun(&A::i), &a)(0);
bind1st(mem_fun(&A::s), &a)("");
Pierwsza linia kompiluje OK, ale drugi generuje błąd:
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 &>
]
Co może być problemem? Jak mogę to naprawić?
Edit:
Wydaje się, że każda teza odniesienia jest problem. Więc jeśli zmienię metodę i
na void i(int &i) {}
, otrzymam podobny błąd.
Biorąc pod uwagę, że jesteśmy w 2011 roku i ma C++ 11 może chcesz przyjrzeć się C++ std :: '11s bind' lub' boost :: wiążą 'które sprawiają, że te rzeczy o rząd wielkości są łatwiejsze w obsłudze. – PlasmaHH
@PlasmaHH: Niestety, nie mogę używać C++ 11 w tym projekcie. –
A także "boost :: bind"? – PlasmaHH