【发布时间】:2013-03-19 08:23:12
【问题描述】:
我有一个基于运行时返回特定设备的类。
struct ComponentDc;
struct ComponentIc;
typedef Device<ComponentDc> DevComponentDc;
typedef Device<ComponentIc> DevComponentIc;
template<class Component>
class Device{
Device<Component>* getDevice() { return this; }
void exec() { }
};
在exec(),如果组件类型是ComponentDc,我想打印“Hello”,如果是ComponentIc,我想打印world。此外,只有这两种类型可以用来创建 Device。
我该怎么做?
【问题讨论】: