Yes there is a template for this, use std::variant instead of void*. I guess your code contains some dynamic casts or worse already to interact with the stored objects. That is bad design in general, type system is our friend, types should not be erased lightly.
发布评论
评论(1)
是的,有一个模板,请使用
std :: variant
而不是void*
。我猜您的代码包含一些动态铸件,或者已经与存储对象进行交互。通常,这是不好的设计,类型系统是我们的朋友,不应轻轻擦除类型。然后,您可以做类似的事情:
Yes there is a template for this, use
std::variant
instead ofvoid*
. I guess your code contains some dynamic casts or worse already to interact with the stored objects. That is bad design in general, type system is our friend, types should not be erased lightly.Then you can do something akin to this: