假设我有一个这样的对象:动态数据类型选择
class Spline {
public:
Spline(std::size_t const dim);
// Quite a few functions here. One of those:
vec operator()(double const t) const; // Returns vector of dimension d
}
现在,在这个类的大多数应用中,尺寸将已经在编译时确定,因此这将是一个很好的想法(因为性能原因)来改变这样的类:
template <std::size_t dim>
class Spline {
public:
Spline();
// Quite a few functions here. One of those:
vec::fixed<dim> operator()(double const t) const; // Returns vector of dimension d
}
(对于那些谁不知道,vec
和vec::fixed
是由犰狳线性代数库定义的对象)。现在我想让两个版本并行运行,从而能够在编译时和运行时选择维度。总之,我想创建相当于vec::fixed<dim>
的Spline::fixed<dim>
,但不实施所有功能两次。特别是,我将不得不根据是否存在模板参数来选择所有这些函数的返回类型。
你有什么想法我可以做到这一点,特别是在清晰和可维护的设计方面思考? (希望我对自己说清楚,这点我不太清楚。)
不应该是'typename Spline :: fixed <10> :: type fixed_10_spline;'? – 2011-04-18 05:03:50
谢谢。我每天都会学到新的东西 - 这次你做到了;) – Thilo 2011-04-18 08:01:57