 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
André Schmidt Guest
|
Posted: Mon Jan 24, 2005 6:18 pm Post subject: stl:list and boost:function/bind as messagehandler |
|
|
Hi newsgroup!
I am in trouble storing boost function-pointers for
object-member-functions in a std:list
defining in Input.h
typedef boost::function2< void, INPUT_EVENT, int> PInputHandler;
std::list<PInputHandler> m_listHandler;
void CInput::RegisterTarget( PInputHandler pHandler )
{
m_listHandler.push_back(pHandler);
}
using in an instance of CCtrlButton
g_input.RegisterTarget(boost::bind( &CCtrlButton::HandleInputEvents,
this, _1, _2 ) );
All works fine until i want to remove a pointer from the list:
void CInput::ReleaseTarget( PInputHandler pHandler )
{
m_listHandler.remove(pHandler);
}
MSVC6 gives the following Error in the definition of std::list::remove
D:ProgrammeMicrosoft Visual StudioVC98INCLUDElist(280) : error
C2451: Bedingter Ausdruck des Typs 'void' nicht zulaessig
Ausdruck vom Typ void kann nicht in andere Typen konvertiert werden
D:ProgrammeMicrosoft Visual StudioVC98INCLUDElist(278) :
Bei der Kompilierung der Member-Funktion 'void __thiscall
std::list<class boost::function2
std::allocator<class boost::function2
UT_EVENT,int,int> > >::remove(const class boost::function2<void,enum
INPUT_EVENT,int,int> &)' der Klassenvorlage
excuse me that it is in german language, i try to translate it:
"Conditional expression of type 'void' is not valid. Expression of type
void cannot be cast into other types"
here is the definition of std::list::remove
void remove(const _Ty& _V)
{iterator _L = end();
for (iterator _F = begin(); _F != _L; )
if (*_F == _V)
erase(_F++);
else
++_F; }
Something i missed?
I think its the comparison of the to handler-objects that did notwok.
Thanks in advance,
André
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
doug.gregor@gmail.com Guest
|
Posted: Tue Jan 25, 2005 5:20 am Post subject: Re: stl:list and boost:function/bind as messagehandler |
|
|
It is not possible to compare two Boost.Function objects (because it
can't be implemented "well"). However, recent versions of
Boost.Function can be compared against any type that they can store.
For instance:
function<int(int, int)> f;
function<int(int, int)> g;
if (f == g) ; // ERROR! cannot do this
f = std::plus<int>();
assert(f == std::plus<int>()); // OK
This is enough functionality to implement a template variation of your
ReleaseTarget function, like this:
template<typename Handler>
void ReleaseTarget( const Handler& pHandler )
{
// Can't use remove(), unfortunately, because pHandler would get
converted.
std::list<PInputHandler>::iterator i = m_listHandler.begin();
while (i != m_listHandler.end()) {
if (*i == pHandler) i = m_listHandler.erase(i);
else ++i;
}
}
Doug Gregor
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|