在代碼:如何將參數傳遞給策略的構造函數?
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