This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problems with ambiguous definiton in templated code


Hi there

(I assume this is where you send messages, this is my first). I have 
been coding a Signal/Binding mechanism of similar function to sigc++. 
However, upon compiling the code (which has no syntaxical errors as far 
as I can tell) I get the following error message:

bash-2.05$ make sigtultest
g++ -Wall -g -c sigtultest.cc -I./ -I/usr/include/
sigtultest.cc: In function `int main (...)':
sigtultest.cc:22: request for member `Connect' is ambiguous
signal.hh:203: candidates are: template <class _ClassType_> void
Sigtul::_MemberConnectImpl::Connect (_ClassType_ *, typename typename
_CallTraits_::Member<_ClassType_>::Function) [with _ClassType_ =
_ClassType_, _CallTraits_ = Sigtul::_CallTraits0<int>, _SignalImpl_ =
Sigtul::_Signal0Impl<int>::_CallImpl]
signal.hh:216:                 void
Sigtul::_StaticConnectImpl<_CallTraits_, _SignalImpl_>::Connect
(typename _CallTraits_::StaticFunction) [with _CallTraits_ =
Sigtul::_CallTraits0<int>, _SignalImpl_ =
Sigtul::_Signal0Impl<int>::_CallImpl]
make: *** [sigtultest.o] Error 1


How can
template <class _ClassType_>
void Sigtul::_MemberConnectImpl::Connect (_ClassType_ *, typename 
typename _CallTraits_::Member<_ClassType_>::Function)
[with _ClassType_ = _ClassType_, _CallTraits_ = Sigtul::_CallTraits0<int>]

which takes two parameters be even remotely similar to

void Sigtul::_StaticConnectImpl<_CallTraits_, _SignalImpl_>::Connect 
(typename _CallTraits_::StaticFunction)
[with _CallTraits_ = Sigtul::_CallTraits0<int>]

which only takes one? The code that generates the error is posted below.


  template <typename ReturnType>
  class Signal0;

  struct _SignalTraits0
  {
    template <typename ReturnType>
    struct Signal
    {
      typedef Signal0 <ReturnType> SignalType;
    };
  };


  template <typename ReturnType>
  struct _CallTraits0
  {
    typedef _SignalTraits0::Signal<ReturnType> SignalTraits;

    typedef ReturnType (*StaticFunction)();

    template <typename _ClassType_>
    struct Member
    {
      typedef ReturnType (_ClassType_::*Function) ();
    };
 
    typedef ReturnType (*CallbackFunction)( Signal* );
  };

  template <typename _CallTraits_, typename _SignalImpl_>
  struct _MemberConnectImpl : protected virtual Signal, protected 
virtual _SignalImpl_
  {
  public:
    template <typename _ClassType_>
    void Connect ( _ClassType_ *C , typename 
_CallTraits_::Member<_ClassType_>::Function F )
    {
      /*this->MemberFunction = GenericMemberFunction(F);
      this->Class = GenericClass(C);
      this->Callback = &Call<_ClassType_>::Member; */
    }
  };


  template <typename _CallTraits_, typename _SignalImpl_>
  struct _StaticConnectImpl : protected virtual Signal, protected 
virtual _SignalImpl_
  {
  public:
    void Connect ( typename _CallTraits_::StaticFunction F )
    {
      /*  this->StaticFunction = GenericStaticFunction(F);
      this->Class = GenericClass(0);
      this->Callback = &Call<void>::Static;  */
    }
  };

  template <typename _CallTraits_>
  struct _Connection
  {
    template <typename _ClassType_>
    typename _CallTraits_::SignalTraits::SignalType Connect (_ClassType_ 
*C, typename _CallTraits_::Member<_ClassType_>::Function M)
    {
      typename _CallTraits_::SignalTraits::SignalType Func;
      Func.Connect (C, M);
      return Func;
    }
 
    typename _CallTraits_::SignalTraits::SignalType Connect (typename 
_CallTraits_::StaticFunction F)
    {
      typename _CallTraits_::SignalTraits::SignalType Func;
      Func.Connect (F);
      return Func;
    }
  };


  template <typename ReturnType>
  struct _Signal0Impl
  {
    typedef _CallTraits0<ReturnType> CallTraits;

    struct _CallImpl
    {
    protected:
      template <typename Callee>
      class Call
      {
      public:
    static ReturnType Member ( Signal *Func  /*params*/)
    {
      return 
((reinterpret_cast<Callee*>(Func->Class))->*(reinterpret_cast<typename 
CallTraits::Member<Callee>::Function>(Func->MemberFunction)))(/*params*/);
    }
   
    static ReturnType Static ( Signal *Func /*params*/)
    {
      return (reinterpret_cast<typename 
CallTraits::StaticFunction>(Func->StaticFunction))(/*params*/);
    }
      };
     
      typename CallTraits::CallbackFunction Callback;
    };

    class _Signal :
      protected _StaticConnectImpl<CallTraits, _CallImpl >,
      protected _MemberConnectImpl<CallTraits, _CallImpl >
    {
    public:
      _Signal ( void ) {}
      ReturnType operator() ()
      {
    return this->Callback ( this ); 
      }
    };

  };

  template <typename ReturnType>
  class Signal0 : public _Signal0Impl<ReturnType>::_Signal
  {
  };

#include <iostream>

int F ( )
{
  return 2;
}

int main ( ... )
{

  Signal0<int> Sig;

  Sig.Connect ( &F );
 
  std::cout << "The value is: " << Sig() << std::endl;

  return (0);
}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]