Re: [sigc] Range over signals



> While experimenting a bit with libsigc++, I ran into some issues
> regarding the type of a sigc::signal#. The following source shows that
> I'd like to be able to range over sigc::signals no matter its specific
> type and elaborate on that. I've tried to add explicit type information
> regarding the slot (see 'connect(sigc:slot<..'), but without success,
> apparently. Can anyone shed some light in this matter?
>
> 
> class SignalManager
> {
>    public:
>       SignalManager() {}
> 
> //    sigc::signal<void, int>* get_signal()  // <- OK
>       sigc::signal_base* get_signal()        // <- NOT OK
>       {
> 	 return &signal_print;
>       }
>    private:           
>       sigc::signal<void, int> signal_print;
>       
> };
> 
> void on_print(int i)
> {
>    std::cout << i << std::endl;
> }

I've been playing with it a bit and was able to narrow the problem down
somewhat. 

int main()
{
   SignalManager sm;  

   sigc::signal<void, int>* tmp = 
      dynamic_cast<sigc::signal<void, int>*>( sm.get_signal() );

   tmp->connect(sigc::slot<void,int>(sigc::ptr_fun(&on_print)));

   tmp->emit(123);

   return 0;
}

When altering the main-function it showed that it is possible to return
a 'sigc::signal<void, int>*' as a 'sigc::signal_base*'. However, it is
not possible to go the other way around (cast base class pointer to a
derived class pointer) given that my compiler (g++ 4.0.1) 
chokes and tells me that the 'source type is not polymorphic'. Does
anyone got any hints?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]