Need help with boost.variant and apply_visitor method overloading.

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

On Fri, 28 Mar 2008 07:56:59 -0000, Kevin Scarr
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
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
void operator() ( G2Consumer<C>* consumer, G2Producer<P>* producer ) const { G2Base* c = dynamic_cast (consumer); G2Base* p = dynamic_cast (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/
participants (2)
-
Jiri Palecek
-
Kevin Scarr