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