K
Kibiz0r
Basically, I want a templated method to do one thing if the type T has
a constructor that takes a std::istringstream, and another thing if it
doesn't.
The problem is that if I put the T(std::istringstream) call in there,
every type that is used for that method has to have that constructor
or it errors.
Can someone please point me in the right direction?
Here's (a slightly simplified version of) the code, if you want a look
at it.
template<typename T>
T getData() const
{
if (m_data->isSerialized())
{
const EventData<std::istringstream>* data =
dynamic_cast<const
EventData<std::istringstream>*>(m_data);
return T(data->getData());
}
else
{
const EventData<T>* data =
dynamic_cast<const EventData<T>*>(m_data);
return data->getData();
}
}
Thank you!
a constructor that takes a std::istringstream, and another thing if it
doesn't.
The problem is that if I put the T(std::istringstream) call in there,
every type that is used for that method has to have that constructor
or it errors.
Can someone please point me in the right direction?
Here's (a slightly simplified version of) the code, if you want a look
at it.
template<typename T>
T getData() const
{
if (m_data->isSerialized())
{
const EventData<std::istringstream>* data =
dynamic_cast<const
EventData<std::istringstream>*>(m_data);
return T(data->getData());
}
else
{
const EventData<T>* data =
dynamic_cast<const EventData<T>*>(m_data);
return data->getData();
}
}
Thank you!