I have a class template which should be able to return its template type via std::type_info
:
template <class factType>
class Belief : public BeliefRoot
{
/* ... */
factType m_Fact;
std::type_info GetBeliefType() const override
{
return typeid(m_Fact);
}
};
But compiling that class gives me the following error:
error C2280: 'type_info::type_info(const type_info &)': attempting to reference a deleted function
Any ideas what I am missing here?
The issue is unrelated to templates, it's caused because type_info
is non-copyable. Every type_info
object you need is already compiled into your program, and typeid()
doesn't make a new one, it returns a const reference to the existing one.
You should make your GetBeliefType
function return by const
reference:
const std::type_info& GetBeliefType() const override
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With