【发布时间】:2012-12-05 12:32:57
【问题描述】:
这是场景:
class Base {
public:
typedef Base type;
};
class Derived: public Base {
public:
typedef Derived type;
};
我想要类似的东西:
int main() {
Base * bs = new Derived();
decltype(*bs)::type newvar;
}
如何在不使用静态/动态强制转换的情况下执行上述操作来获取派生类的类型?
【问题讨论】:
-
为什么这两个 typedef 需要命名相同?我觉得这可能会给以后的程序造成一些混乱..
-
如果我更改类型名称,我怎样才能让它工作??
标签: c++ templates inheritance polymorphism typedef