I need to store the type of an object in a class.
This would look like:
template<class T>
class box
{
private:
type_info type;
T data;
}
The reason why I need to store the type information is complex to explain, anyway I would know if this is possibile in C++.
When i try to compile an instruction like:
type=typeid(data);
I get a syntax error:
No matching for initialization of ‘std::type_info’
So it seems like type_info hasn’t the constructor with no arguments.Is possibile then in some way, to memorize the type of an object into a data?
typeinfo is noncopyable – its constructors and assignment operator are private (in C++11 they are flagged deleted). you’re probably after something along these lines: