我有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);
我检查了类似的问题,但是找不到解决方案。我确定我在某个地方犯了一个愚蠢的错误,但似乎无法弄清楚。
我希望有人能帮助我。