Boost logo

Boost Users :

From: Jiri Palecek (jpalecek_at_[hidden])
Date: 2008-03-28 11:13:50


On Fri, 28 Mar 2008 07:56:59 -0000, Kevin Scarr <kscarr_at_[hidden]>
wrote:

> I am trying to implement a system for ensuring producers and consumers
> agree on the data type they are exchanging.
>
> However, I also have "general" containers which can send or receive
> anything (mainly routing components).
>
> Anyway, I have tried to setup the following code to implement this
> scheme, however When I compile code (on MSVC 2005), I see the following
> error:
>
> Error 1 error C3066: there are multiple ways that an object of this type
> can be called with these arguments; unable to recover from previous
> error(s); stopping compilation
> c:\boost-1_34_1\boost\variant\detail\apply_visitor_binary.hpp 63
>
>
> I have tracked it down to the first two overloads where I am trying to
> connect a consumer/producer of a specific type to a general
> producer/consumer.
>

At the first glance (i haven't looked at it thoroughly), the call

   your_visitor(G2Consumer<DataTypes>*, G2Producer<DataTypes>*)

is really ambiguous (the first two overloads are the best matches and none
of them better than the other). Just add this overload and things should
work.

Regards
     Jiri Palecek

>
>
> typedef boost::variant<t1*,t2*,t3*> DataTypes;
>
> typedef boost::variant<
> G2Consumer<t1>*,
> G2Consumer<t2>*,
> G2Consumer<t3>*,
> G2Consumer<DataTypes>* > G2ConsumerTypes;
>
> typedef boost::variant<
> G2Producer<t1>*,
> G2Producer<t2>*,
> G2Producer<t3>*,
> G2Producer<DataTypes>* > G2ProducerTypes;
>
>
> class doConnectConsumerToProducer : public static_visitor<>
> {
> public:
//add:
       void operator() ( G2Consumer<DataTypes>* consumer,
                         G2Producer<DataTypes>* producer ) const;

> template<typename T>
> void operator() ( G2Consumer<DataTypes>* consumer,
> G2Producer<T>* producer ) const
> {
> consumer->RegisterAsConsumer( *producer );
> }
>
> template<typename T>
> void operator() ( G2Consumer<T>* consumer,
> G2Producer<DataTypes>* producer ) const
> {
> consumer->RegisterAsConsumer( *producer );
> }
>
> template<typename T>
> void operator() ( G2Consumer<T>* consumer,
> G2Producer<T>* producer ) const
> {
> consumer->RegisterAsConsumer( *producer );
> }
>
> template<typename C, typename P>
> void operator() ( G2Consumer<C>* consumer,
> G2Producer<P>* producer ) const
> {
> G2Base* c = dynamic_cast<G2Base*>(consumer);
> G2Base* p = dynamic_cast<G2Base*>(producer);
>
> std::ostringstream msg;
>
> msg << "Incompatible consumer(" << typeid(*c).name()
> << ") and producer(" << typeid(*p).name()
> << ") types" << std::ends;
>
> throw G2::exception( msg.str().c_str() );
> }
> };
>
> // Helper function to drive this above.
> void connectConsumerToProducer( G2ConsumerTypes& c, G2ProducerTypes& p )
> {
> apply_visitor( doConnectConsumerToProducer(), c, p );
> }

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net