【发布时间】:2013-10-26 08:03:51
【问题描述】:
我有以下结构:
class Base {
virtual T foo() = 0;
};
class Derived : public Base {
T foo() override { /**/ }
}
class Derived1 : public Base {
T foo() override { /**/ }
}
我需要以下工作(或适当的替代品):
some_container<unique_ptr<Base>> objects;
基本上,
C++ AMP 不允许在内核中使用虚函数,但我肯定需要类似继承链的容器行为。
将这种继承链转换为模板魔法的推荐/常见模式是什么?
【问题讨论】:
-
看看
boost::variant。这可能有助于获得不同类型的通用列表。 -
相关stackoverflow.com/questions/18859699/… 如果您认为这是骗子,请告诉我! (嗨!Gauntlet 还在吗?)
-
Gauntlet 还在地上,只是有点忙于生活:)。链接的东西有一些有用的想法,我会仔细看看。
-
@sehe 哦,是的,boost::variant 可能会,谢谢。
-
或者这有点像similar discussion/example in the lounge(也链接到所有重要的 Sean Parent 谈话 "Inheritance Is The Base Class of Evil")