class A {}
A a;
type_info info = typeid (a); // error type_info is private
i want a list list<type_info>
to store the type of classes. Is there a solution?
RTTI for basic types such as int and bool is stored in the run-time library. Therefore, object files generated from a C++ program might reference RTTI defined in libc++abi.
std::type_info The class type_info holds implementation-specific information about a type, including the name of the type and means to compare two types for equality or collating order. This is the class returned by the typeid operator.
You can't create copies of 'type_info' objects. However, the result if 'typeid' is an Lvalue and the corresponding 'type_info' objects, once obtained, continue to live till the end of the program. For these reasons, you can safely store pointers to 'type_info' objects in your list.
You cannot instantiate objects of the type_info class directly, because the class has only a private copy constructor. Since the list needs copy constructor...
If you really need it, use std::list< type_info*>.
I don't know why you need this list, but I would think to an alternative design, not involving RTTI, if possible.
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