c++ - 模板函数未在此范围内声明
问题描述
我有一个 SplineCreator 类的头文件和一个 cpp 文件。这里面有一个函数叫做 CreateLinearSpline 和 CreateCubicSpline。这里:-(注意:这不是一个完整的头文件,但这些是我感兴趣的函数。我也在 cpp 文件中定义了这些函数。所有的头文件都包含在顶部)
template <typename T> class SplineCreator {
public:
Spline<T> CreateLinearSpline(const std::vector<T>& y_values, const T x_diff = 1.0);
Spline<T> CreateCubicSpline(const std::vector<T>& y_values,
const std::array<T, 2> boundary_values = std::array<T, 2>{ { 0.0, 0.0 } },
const std::array<BoundaryType, 2> boundary_type
= std::array<BoundaryType, 2>{ { first_deriv, first_deriv } },
const T x_diff = 1.0);
}
我在另一个 cpp 文件中使用了这些函数,如下所示:
template <typename T> Path<T>::Path(const std::vector<Point2D<T>>& point_vector,
const T x_diff, const T gradient_start, const T gradient_end, const size_t degree)
{
VectorXY<T> xy_vec;
Point2D<T>::create_x_y_vectors(point_vector);
Expects(degree > 0);
std::array<T, 2> boundary_values{ { gradient_start, gradient_end } };
Spline<T> x_spline;
Spline<T> y_spline;
switch (degree) {
case 1:
x_spline = CreateLinearSpline(xy_vec.x, x_diff);
y_spline = CreateLinearSpline(xy_vec.y, x_diff);
case 3:
x_spline = CreateCubicSpline(xy_vec.x, boundary_values,
std::array<BoundaryType, 2>{ { first_deriv, first_deriv } }, x_diff);
y_spline = CreateCubicSpline(xy_vec.y, boundary_values,
std::array<BoundaryType, 2>{ { first_deriv, first_deriv } }, x_diff);
default:
throw std::invalid_argument("The Degree should be either 1 or 3");
}
Path(x_spline, y_spline);
}
另外,我已经在这个文件的顶部包含了所有的头文件。但是当我使用 catkin_make 编译它时,出现以下错误:
错误:未在此范围内声明“CreateLinearSpline” x_spline = CreateLinearSpline(xy_vec.x, x_diff);
错误:未在此范围内声明“CreateLinearSpline”,并且在实例化点通过依赖于参数的查找未找到任何声明 [-fpermissive] y_spline = CreateLinearSpline(xy_vec.y, x_diff);
我检查了类似的问题,但找不到解决方案。我确信我在某个地方犯了一个愚蠢的错误,但我似乎无法弄清楚这一点。
我希望有一个人可以帮助我。
解决方案
推荐阅读
- python - 如何在 Flask 函数中将击键传递给子进程?
- c# - 选择歌曲后 Mp3 播放器滞后 (c#)
- python - 向我的数组追加或插入随机元素
- c++ - 运行时错误:以下代码的运行时错误分段错误 (SIGSEGV)
- c# - Pulumi 本地工作区配置值,这些是否适用于 Azure 部署?
- python - 如何使用 environment.yaml 文件在 Python 中创建虚拟环境?
- amazon-s3 - 如何限制 S3 分段上传总大小
- amazon-s3 - 如何确定 s3 文件是否已使用服务器端加密进行加密
- javascript - Sql Server - 约束 - Sequelize - 仅当 B 列为空时才允许设置 A 列,反之亦然
- python - NotImplementedError:无法将符号张量转换为 numpy 数组