【发布时间】:2009-09-05 21:42:47
【问题描述】:
目前,我有一些代码如下
template<typename Type>
Type* getValue(std::string name, bool tryUseGetter = true)
{
if(tryUseGetter)
{
if(_properties[name]->hasGetter)
{
return (Type*)_properties[name]->getter();
}
return (Type*)_properties[name]->data;
}
else
{
return (Type*)_properties[name]->data;
}
}
有没有办法让 tryUseGetter 成为编译时开关?即将它移动到模板声明,所以它类似于这个
template<typename Type, bool tryUseGetter = true>
...
谢谢。
【问题讨论】:
标签: c++ optimization templates gcc