【发布时间】:2020-03-23 08:48:24
【问题描述】:
说我有
class A {
};
class B {
};
using AOrB = boost::variant <A,B>;
A* ptr2a = ....
AOrB* another_ptr2a = a;//this doesn't compile for me, what is the correct way to do it?
使用 boost::variant* 是一种不好的做法吗?
【问题讨论】:
-
“使用 boost::variant* 是一种不好的做法吗?” ——几乎可以肯定。除此之外,您想要的根本无法完成:不能将
A*分配给A。 -
variant<A, B>*!=variant<A*, B*>. -
variant<A, B>包含A或B,而不是A*。由于尚不清楚您实际想要实现什么,因此我投票决定关闭以进行澄清。
标签: c++ boost-variant