我正在探索C++(C++ 11)中的模板shenanigans,我想要的一件事是抽象类中的纯虚拟类型。这就像斯卡拉的abstract types。在C + +我想要做的事情如下:C++:纯虚拟类型
struct Base {
// Says any concrete subclass must define Type, but doesn't
// require that it be anything in particular.
virtual typedef MyType;
};
struct Derived : Base {
// Won't compile unless this typedef exists.
typedef int MyType;
};
任何想法如何做到这一点?
为什么需要这个? – Xeo 2013-03-04 19:46:14
你想要什么?知道你的目标肯定会让你更好地回答问题。不,“模拟一些随机的Scala功能”不算作目标。 – 2013-03-04 19:46:16
@Xeo - 海报是“探索模板shenanigans” - 这是一个人为设定的目标,但仍然是一个目标! :) – wilsonmichaelpatrick 2013-03-04 20:08:30