我试图编写一个小的C++重新实现GSL集成例程作为一个实践项目来学习C++元编程。我有以下问题。模板参数向量::构造函数
我已经定义了一些类型的特性(使程序与双浮筒和工作两者)
template<typename T> class IntegrationWorkspaceTraits;
template<> class IntegrationWorkspaceTraits<double>
{
public:
typedef double ft; //float_type
static constexpr ft zero = 0.0;
};
template<> class IntegrationWorkspaceTraits<float>
{
public:
typedef float ft; //float_type
static constexpr ft zero = 0.0f;
};
现在我有一个使用这种特质,像这样
template< typename T, typename AT = IntegrationWorkspaceTraits<T> > GslIntegrationWorkspace
{
typedef typename AT::ft ft;
typedef typename AT::zero zero;
public:
GslIntegrationWorkspace(size_t size);
private:
typename std::vector<ft> alist;
}
类
我的问题是:如何使用定义在特征上的零常量来设置成员矢量的初始值。我的猜测是一样的东西
template<typename T, typename AT>
GslIntegrationWorkspace::GslIntegrationWorkspace(size_t size):
alist(size, typename AT::zero),
{};
但是编译器G ++抱怨 “gsl_integration.h:63:42:错误:无效使用模板名称 'GslIntegrationWorkspace' 没有一个参数列表”
最好
你真的需要一个特质让你回到'T'和'T()'吗?这看起来像是完全矫枉过正......'alist(size)'会有完全相同的行为。 –