[vos-d] Message handler problem

Ken Taylor taylork at alum.mit.edu
Fri Mar 16 02:12:46 EDT 2007


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 ;)

-Ken




More information about the vos-d mailing list