[vos-d] Message handler problem
Ken Taylor
taylork at alum.mit.edu
Fri Mar 16 02:39:31 EDT 2007
Ken Taylor wrote:
> Reed Hedges wrote:
> > Peter Amstutz wrote:
> > > Try
> > >
> > > template<class T> register() {
> > > VobjectBase::registerHandler<T>("message", &T::handler);
> > > }
> > >
> > > (note T::handler)
> >
> > Same problem -- it can't use the method in the base class when the
> > template parameter is the derived class--
> >
>
> Could you use casting to make the compiler happy? Something like:
>
> template<class T> register() {
> VobjectBase::registerHandler<T>("message", ( void (T::*)(Message*) )
> &handler);
> }
>
> ... it should be safe to cast a pointer-to-base-class-member down to a
> pointer-to-derived-class-member. Maybe a dynamic_cast is necessary instead
> (especially in the case of a virtual derived class)? But I'm too lazy to
> actually test any of this out right now ;)
>
http://www.kuzbass.ru:8086/docs/isocpp/conv.html#conv.mem
Ick... it looks like you can't do this conversion with virtual inheritance
:/
What the hell? If member function pointers are smart enough to resolve
virtual functions, then why couldn't they resolve virtual inheritance, given
that there's enough information to recognize that it's virutal inheritance
at compile-time?
Oh well. Looks like you might just have to add a message-handler stub in the
derived class that calls the base class or something, then use Peter's
method for registering it.
-Ken
More information about the vos-d
mailing list