Boost logo

Boost Users :

From: Kevin Scarr (kscarr_at_[hidden])
Date: 2008-03-28 03:56:59


Hi

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.

What am I doing wrong? The compiler obviously thinks that it can cast a
(for example) G2Consumer<t1>* into a G2Consumer<DataTypes>*, so it
cannot resolve which overload to use. How can I tell it not to cast??

Thanks for your help,
Kevin

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


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