在代码:如何将参数传递给策略的构造函数?
template<class T>
struct FactorPolicy
{
T factor_;
FactorPolicy(T value):factor_(value)
{
}
};
template<class T, template<class> class Policy = FactorPolicy>
struct Map
{
};
int _tmain(int argc, _TCHAR* argv[])
{
Map<int,FactorPolicy> m;//in here I would like to pass a double value to a
//FactorPolicy but I do not know how.
return 0;
}
编辑 [马克H]
template<class T, template<class> class Policy = FactorPolicy>
struct Map : Policy<double>
{
Map(double value):Policy<double>(value)
{
}
};
为什么你想要它? – 2010-10-31 19:56:20
@Alexey如果你看看FactorPolicy的ctor,有一个arg被传递,我希望能够在声明变量Map时传递这个值。像这样:Map –
2010-10-31 20:02:12