首页 > 解决方案 > 专门为部分模板特化设置的类中的 C++ 覆盖函数

问题描述

我正在编写一个具有多个功能的点云类(使用 Eigen 作为线性代数库)。我想为 3 维点云实现一些特定的功能。因此,我以以下方式实现了通用类层次结构,其中我部分专门化了点云的模板参数之一:

template <typename T, unsigned int DIM>
class PointCloudBase {
   public:
    using Vector = Eigen::Matrix<T, DIM, 1>;
    using Hyperplane = Eigen::Hyperplane<T, DIM>;
    using MatrixDIM = Eigen::Matrix<T, DIM, DIM>;
    using AlignedBox = Eigen::AlignedBox<T, DIM>;

    bool convexHullIntersects(const AlignedBox& box) const {
       // generic implementation for this function
    }

    // more stuff here

};


template<typename T, unsigned int DIM>
class PointCloud : public PointCloudBase<T, DIM> {

};


template<typename T>
class PointCloud<T, 3U> : public PointCloudBase<T, 3U> {
  public:

    using typename PointCloudBase<T, 3U>::AlignedBox;
    using typename PointCloudBase<T, 3U>::Vector;
    bool convexHullIntersects(const AlignedBox& box) const override {
      // implementation specific to DIM = 3U
    }
};

但是,当我尝试将类实例化为 时PointCloud<double, 3U> pc;,我收到以下错误,抱怨 convehullIntersection 没有覆盖任何内容:

error: ‘bool PointCloud<T, 3>::convexHullIntersects(const typename PointCloudBase<T, 3>::AlignedBox&) const [with T = double; typename PointCloudBase<T, 3>::AlignedBox = Eigen::AlignedBox<double, 3>]’ marked ‘override’, but does not override

这里有什么问题?

谢谢!

标签: c++c++11

解决方案


推荐阅读