A type-safe equivalent of the void* pointer.
any_ptr accepts a pointer of any type, and keeps the memory address along with the pointer's type. The pointer can be extracted from any_ptr with the exact same type it was used to store it. This was achieved with the use of template methods, typeid() and std::type_info.
The primary use of any_ptr is with cClassDescriptor.
Important: Since std::type_info knows nothing about inheritance relationships, any_ptr cannot perform any upcast or downcast when extracting the pointer.
The following code snippet raises a runtime error:
When casting is important (~always), the toAnyPtr()/fromAnyPtr() functions should be used for converting an object pointer to and from any_ptr. Most toAnyPtr()/fromAnyPtr() functions are generated by the message compiler from .msg files.
Updated code snippet: