I have a stream of data which is contained in a System::Collections::Queue
. My data source can output the same data to multiple streams but to do so, needs to duplicate the data for each one. I currently do the following:
void DataGatherer::AddMyDataToQueues(MyData^ data)
{
// Send duplicates to all queues
for( int i = 0; i < m_outputQueues->Count; i++ )
{
AddResultToQueue(gcnew MyData(data), (Queue^)m_outputQueues[i]);
}
}
Which works fine as long as I'm sending MyData
objects. Lets say I want to send MyOtherData
objects as well though. It would be nice to do something more generic like this:
void DataGatherer::AddDataToQueues(Object^ obj)
{
// Send duplicates to all queues
for( int i = 0; i < m_outputQueues->Count; i++ )
{
AddResultToQueue(gcnew Object(obj), (Queue^)m_outputQueues[i]);
}
}
...but that won't compile because:
1>.\DataGatherer.cpp(72) : error C3673: 'System::Object' : class does not have a copy-constructor
So is it possible to duplicate an object without knowing its type? ..and if so, how do I do it? :)